PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Variables: Declaration, Initialization and Scope in C (वैरिएबल्स: डिक्लेरेशन, इनिशियलाइज़ेशन, स्कोप और लाइफटाइम) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: A variable in C is a named memory storage location bound to a type whose visibility, persistence, and cross-file sharing are governed by Scope (Block, File, Function, Prototype), Storage Duration (Automatic, Static, Allocated), and Linkage. Understanding Declaration vs Definition, uninitialized garbage vs zero-initialization, and the four storage classes (auto, register, static, extern) eliminates subtle lifetime bugs.
अध्याय सार: C में वेरिएबल एक नामित मेमोरी स्थान है जिसकी दृश्यता (Scope: Block, File, Function, Prototype), जीवनकाल (Lifetime: Automatic, Static, Allocated) और लिंकेज (None, Internal, External) स्टोरेज क्लासेस द्वारा नियंत्रित होते हैं। डिक्लेरेशन बनाम डेफिनिशन, ऑटोमैटिक गार्बेज मान बनाम स्टैटिक शून्य-प्रारंभिकरण तथा auto, register, static, extern का ज्ञान बग-रहित C कोड के लिए आवश्यक है।
Variables: Declaration, Initialization and Scope in C: Detailed Notes & Architecture (वैरिएबल्स: डिक्लेरेशन, इनिशियलाइज़ेशन, स्कोप और लाइफटाइम)
1. Declaration vs Definition & Initialization vs Assignment (डिक्लेरेशन बनाम डेफिनिशन और इनिशियलाइज़ेशन बनाम असाइनमेंट)
[EN] A Declaration introduces an identifier's name and data type to the compiler without allocating storage (e.g., 'extern int count;' or 'int add(int, int);'), whereas a Definition allocates actual memory storage ('int count;' or 'int count = 5;'). Every definition is a declaration, and the One Definition Rule permits multiple declarations across files yet strictly ONE external definition. Initialization supplies a variable's starting value at creation ('int x = 10;'), while Assignment alters an existing variable afterward ('x = 20;'); notably, const variables MUST be initialized when defined because later assignment fails.
[HI] डिक्लेरेशन ('extern int x;') कंपाइलर को केवल नाम और टाइप बताता है बिना मेमोरी आरक्षित किए, जबकि डेफिनिशन ('int x;') वास्तविक RAM स्थान आवंटित करती है। निर्माण के समय प्रारंभिक मान देना Initialization ('int x = 10;') है, जबकि बाद में मान बदलना Assignment ('x = 20;') कहलाता है; const वेरिएबल को परिभाषा के समय ही इनिशियलाइज़ करना अनिवार्य होता है।
2. Four Scopes in ISO C & Variable Shadowing (ISO C के चार स्कोप और वेरिएबल शैडोइंग)
[EN] Scope defines the region of source text where a variable name is visible: (1) Block Scope—local variables and parameters visible from declaration until closing '}'; (2) File Scope—global variables declared outside all functions, visible until end of the .c file; (3) Function Scope—applies EXCLUSIVELY to goto labels throughout the entire enclosing function body; and (4) Function Prototype Scope—parameter names inside 'int f(int a, int b);' ending at ')'. Declaring an inner block variable with the same name as an outer/global variable shadows (hides) the outer variable temporarily without modifying its value.
[HI] C में चार स्कोप होते हैं: (1) Block Scope (फंक्शन या { } ब्लॉक के भीतर के लोकल वेरिएबल), (2) File Scope (सभी फंक्शन्स से बाहर घोषित ग्लोबल वेरिएबल), (3) Function Scope (जो केवल goto लेबल्स पर लागू होता है) और (4) Function Prototype Scope (केवल प्रोटोटाइप के कोष्ठकों के भीतर)। यदि अंदरूनी ब्लॉक में बाहरी या ग्लोबल नाम जैसा ही नया वेरिएबल बनाया जाए, तो वह बाहरी वेरिएबल को छिपा (Shadow) देता है।
3. Default Initial Values: Automatic Garbage vs Static/Global Zero (डिफ़ॉल्ट प्रारंभिक मान: ऑटोमैटिक गार्बेज बनाम स्टैटिक/ग्लोबल शून्य)
[EN] Variables declared inside blocks without 'static' have Automatic storage duration (allocated on the call stack upon block entry and destroyed on exit). Uninitialized automatic locals contain indeterminate garbage values—reading them causes Undefined Behavior. Conversely, global variables (file scope) and 'static' local variables occupy static memory (.data if explicitly initialized non-zero, or .bss if uninitialized/zero) and are guaranteed by ISO C to be zero-initialized (0 / NULL) before main() begins.
[HI] फंक्शन के भीतर सामान्य (auto) लोकल वेरिएबल्स कॉल स्टैक पर बनते हैं; बिना मान दिए इन्हें पढ़ने पर अनिश्चित गार्बेज मान मिलता है जो अपरिभाषित व्यवहार (UB) उत्पन्न करता है। इसके विपरीत, सभी ग्लोबल वेरिएबल्स व static लोकल वेरिएबल्स (.bss/.data सेगमेंट) को ISO C द्वारा प्रोग्राम शुरू होने से पहले स्वतः शून्य (0 या NULL) से इनिशियलाइज़ किया जाता है।
4. Storage Classes: auto, register, static, extern & Heap Lifetime (स्टोरेज क्लासेस (auto, register, static, extern) व हीप लाइफटाइम)
[EN] C defines four storage-class specifiers: 'auto' (default local, block scope, stack lifetime, no linkage), 'register' (hints CPU register placement for locals; forbids applying address-of operator & in C!), 'static' (on locals: preserves value across function calls for program lifetime while keeping block scope; on globals/functions: grants Internal Linkage restricting visibility to one .c file), and 'extern' (references a global defined in another .c file with External Linkage). Dynamic memory allocated via malloc() has Allocated storage duration on the heap until explicitly freed.
[HI] चार स्टोरेज क्लासेस हैं: auto (डिफ़ॉल्ट लोकल, स्टैक), register (तेज गति हेतु CPU रजिस्टर संकेत; इस पर & एड्रेस ऑपरेटर अवैध है!), static (लोकल होने पर मान को फंक्शन कॉल्स के बीच सुरक्षित रखता है, और ग्लोबल होने पर इंटरनल लिंकेज से केवल उसी फाइल तक सीमित रखता है), तथा extern (अन्य फाइल के ग्लोबल को जोड़ने हेतु एक्सटर्नल लिंकेज)। डायनामिक malloc() मेमोरी हीप पर free() होने तक बनी रहती है।
Syntax, Formula & Technical Example (Variables: Declaration, Initialization and Scope in C)
#include <stdio.h>
int g_total; /* File scope (.bss): auto-initialized to 0 */
void tick(void) {
static int calls = 0; /* Block scope, static lifetime -> retains value */
int temp = 5; /* Automatic stack variable (recreated per call) */
calls++;
printf("calls=%d temp=%d g_total=%d\n", calls, temp, g_total);
}
int main(void) {
int g_total = 99; /* Shadows global g_total only inside main() */
tick(); tick(); /* Output: calls=1 ... then calls=2 ... */
printf("main shadowed g_total=%d\n", g_total);
return 0;
}
Variables: Declaration, Initialization and Scope in C Quick Reference & Comparison Table
| Storage Class | Memory Segment & Default Value | Scope, Lifetime & Linkage |
|---|---|---|
| auto (Default Local) | Call Stack; Indeterminate (Garbage) value | Block scope; function-call lifetime; No linkage |
| register | CPU Register hint; Indeterminate value | Block scope; address-of (&var) is ILLEGAL in C |
| static | .data / .bss segment; Zero (0 / NULL) | Program lifetime; Local=Block scope, Global=Internal linkage |
| extern | .data / .bss (defined in another unit); Zero (0) | File/Block scope; Program lifetime; External linkage |
Variables: Declaration, Initialization and Scope in C Top 20 Bilingual MCQs with Answers
Q1. What is the fundamental distinction between a Variable Declaration and a Variable Definition in C?
(C में वेरिएबल डिक्लेरेशन (Declaration) और वेरिएबल डेफिनिशन (Definition) के बीच मूल अंतर क्या है?)
(A) There is zero difference in C
(B) A declaration announces name and type (e.g., extern int x;), whereas a definition also allocates memory storage (e.g., int x;)
(C) A declaration allocates RAM while a definition only adds comments
(D) Definitions are written inside .h headers and declarations inside .c only
Correct Answer: (B)
[EN] Memory is reserved only at the definition; multiple 'extern' declarations across files all refer to that single definition.
[HI] डिक्लेरेशन केवल नाम व टाइप बताता है (जैसे extern int x;), जबकि डेफिनिशन वास्तविक मेमोरी आवंटित करती है।
Q2. What value does an uninitialized 'auto' (local) variable hold versus an uninitialized 'static' or global variable?
(बिना प्रारंभिक मान दिए गए लोकल 'auto' वेरिएबल बनाम 'static' या ग्लोबल वेरिएबल में डिफ़ॉल्ट रूप से क्या मान होता है?)
(A) auto local holds indeterminate garbage; static and global are guaranteed zero-initialized (0)
(B) Both hold -1
(C) auto is 0; static holds garbage
(D) Both auto and static are guaranteed 0
Correct Answer: (A)
[EN] Automatic stack slots inherit leftover stack bytes, while .bss static/global storage is zeroed by OS/CRT before main().
[HI] स्टैक पर बनने वाले लोकल auto वेरिएबल में गार्बेज मान रहता है, जबकि .bss में स्थित static/ग्लोबल स्वतः 0 से प्रारंभ होते हैं।
Q3. Which entity in C is the ONLY language construct that possesses 'Function Scope'?
(C भाषा में एकमात्र कौन सा तत्व 'Function Scope' रखता है?)
(A) Global extern variables
(B) Local int variables inside functions
(C) Function prototype parameter names
(D) goto labels (e.g., err_exit:)
Correct Answer: (D)
[EN] ISO C defines Function Scope exclusively for labels used with goto, meaning a label is visible anywhere in its function (even above its definition), unlike block-scoped variables.
[HI] ISO C में Function Scope केवल goto लेबल्स को प्राप्त होता है, जो अपने पूरे फंक्शन के भीतर कहीं से भी लक्षित किए जा सकते हैं।
Q4. What happens if you apply the address-of operator (&) to a 'register' variable in C (e.g., register int x = 5; int *p = &x;)?
(यदि C में किसी 'register' वेरिएबल पर एड्रेस ऑपरेटर (&) लगाया जाए (जैसे int *p = &x;), तो क्या होगा?)
(A) It silently moves x into heap memory
(B) Compile-time error, because CPU registers do not have addressable RAM memory addresses
(C) It executes normally only with -O2 optimization
(D) It prints the CPU register number such as RAX
Correct Answer: (B)
[EN] Because a register variable may reside in a CPU hardware register rather than RAM, C strictly prohibits '&x' (unlike C++ which ignores register).
[HI] CPU रजिस्टर का कोई RAM एड्रेस नहीं होता, इसलिए C में register वेरिएबल पर & (Address-of) लगाना कंपाइल त्रुटि देता है।
Q5. What output does calling fun() three times produce for: void fun(void) { static int c = 1; printf("%d ", c++); }
(यदि fun() को तीन बार कॉल किया जाए जहाँ 'static int c = 1; printf("%d ", c++);' लिखा हो, तो आउटपुट क्या आएगा?)
(A) 1 3 5
(B) 1 2 3
(C) 1 1 1
(D) Garbage values
Correct Answer: (B)
[EN] A static local variable initializes only ONCE before/on first entry and retains its modified value across subsequent calls.
[HI] static लोकल वेरिएबल केवल एक बार इनिशियलाइज़ होता है और पूरे प्रोग्राम के दौरान अपना मान सुरक्षित रखता है, अतः 1 2 3 प्रिंट होगा।
Q6. What effect does placing the 'static' keyword on a file-scope (global) variable or helper function have?
(किसी फाइल-स्कोप (ग्लोबल) वेरिएबल या फंक्शन के आगे 'static' लगाने से क्या प्रभाव पड़ता है?)
(A) It gives Internal Linkage, hiding that variable or function from all other .c translation units
(B) It makes the variable immutable like const
(C) It exports the symbol publicly to external DLLs
(D) It converts the global variable into a stack variable
Correct Answer: (A)
[EN] File-scope static encapsulates private module state, preventing symbol clashes during linking across large multi-file projects.
[HI] फाइल-स्कोप static इंटरनल लिंकेज देता है जिससे वह सिंबल केवल उसी .c फाइल तक सीमित रहता है और अन्य फाइलों से टकराता नहीं।
Q7. Consider: int x = 10; int main(void) { int x = 20; { int x = 30; printf("%d ", x); } printf("%d", x); } What prints?
(कोड 'int x=10; int main(){ int x=20; { int x=30; printf("%d ", x); } printf("%d", x); }' का आउटपुट क्या होगा?)
(A) 30 30
(B) 30 20
(C) Compile error: redeclaration of x
(D) 10 10
Correct Answer: (B)
[EN] Inner block x = 30 shadows main's x = 20 while inside { }, then vanishes on block exit leaving main's x = 20 intact.
[HI] अंदरूनी ब्लॉक में x = 30 बाहर के x = 20 को शैडो करता है; ब्लॉक समाप्त होते ही main का x = 20 पुनः सक्रिय हो जाता है।
Q8. In file.c, what does writing 'extern int count = 42;' represent according to the ISO C standard?
(ISO C मानक के अनुसार किसी फाइल में 'extern int count = 42;' लिखना क्या माना जाता है?)
(A) Always a syntax error in every context
(B) A block-scoped auto variable
(C) A Definition (because an explicit initializer overrides extern's pure-declaration nature)
(D) A pure declaration with zero memory allocated
Correct Answer: (C)
[EN] Adding an initializer '= 42' forces the compiler to allocate storage and initialize it, making it a definition (which triggers a warning if placed inside a block).
[HI] यद्यपि extern सामान्यतः डिक्लेरेशन होता है, पर '= 42' प्रारंभिक मान जुड़ते ही यह मेमोरी आवंटित करने वाली डेफिनिशन बन जाता है।
Q9. Where are function parameters (e.g., a and b in 'void calc(int a, int b)') stored and what is their scope?
('void calc(int a, int b)' में फंक्शन पैरामीटर a और b का स्कोप व स्टोरेज क्या होता है?)
(A) Function Prototype scope lasting across all files
(B) Allocated heap storage until free()
(C) File scope with Static storage duration
(D) Block scope (function body) with Automatic storage duration (call stack / ABI registers)
Correct Answer: (D)
[EN] Parameters behave identically to automatic local variables initialized by the caller's argument values on entry.
[HI] फंक्शन पैरामीटर्स कॉल स्टैक पर ऑटोमैटिक स्टोरेज और फंक्शन के ब्लॉक स्कोप के साथ कार्य करते हैं।
Q10. If a local variable 'const int pin;' is declared inside main() WITHOUT initialization, what happens?
(यदि main() के भीतर 'const int pin;' बिना प्रारंभिक मान दिए घोषित किया जाए और बाद में 'pin = 1234;' लिखा जाए, तो क्या होगा?)
(A) pin is treated as static and set to 1234
(B) pin cleanly becomes 1234
(C) Compile-time error when assigning 'pin = 1234;' because const objects cannot be assigned after creation
(D) Runtime crash
Correct Answer: (C)
[EN] Initialization occurs at definition; a const local left uninitialized cannot even be given a valid value afterward!
[HI] const वेरिएबल में बाद में असाइनमेंट (pin = 1234) करना अवैध है; इसे डिक्लेरेशन के समय ही इनिशियलाइज़ करना होता है।
Q11. Why can an initializer for a 'static' local variable NOT call a runtime function like 'static int r = get_val();'?
('static int r = get_val();' की तरह किसी स्टैटिक लोकल वेरिएबल को रनटाइम फंक्शन कॉल से इनिशियलाइज़ क्यों नहीं किया जा सकता?)
(A) static forbids the = operator completely
(B) Static variables cannot hold int values
(C) Static objects are initialized before main() at compile/load time, requiring constant expressions only
(D) Functions cannot return values to local variables
Correct Answer: (C)
[EN] Because static lifetime starts prior to execution, ISO C mandates compile-time constant initializers for static storage duration.
[HI] स्टैटिक वेरिएबल प्रोग्राम शुरू होने से पहले ही मेमोरी में तैयार हो जाते हैं, इसलिए उन्हें केवल कंपाइल-टाइम स्थिरांक से ही इनिशियलाइज़ किया जा सकता है।
Q12. Which storage class has 'Allocated' storage duration rather than Automatic or Static duration?
(निम्नलिखित में से किसकी मेमोरी लाइफटाइम Automatic या Static न होकर 'Allocated' (Heap) होती है?)
(A) Global variables declared above main()
(B) Variables declared with register
(C) Memory blocks returned by malloc(), calloc(), or realloc()
(D) Local non-static variables inside a loop
Correct Answer: (C)
[EN] Heap allocations survive across function returns until free() is called explicitly (or process exit).
[HI] malloc()/calloc() से प्राप्त हीप मेमोरी की अवधि Allocated होती है जो free() करने तक जीवित रहती है।
Q13. In a two-file project (a.c defines 'int score = 100;'), how does b.c access and modify that same variable?
(दो फाइलों वाले प्रोजेक्ट में (जहाँ a.c में 'int score = 100;' परिभाषित है), b.c उसी वेरिएबल को कैसे एक्सेस कर सकता है?)
(A) By writing 'auto int score;' in b.c
(B) By declaring 'extern int score;' in b.c (or a shared header)
(C) By writing 'static int score;' in b.c
(D) By writing 'int score = 0;' again in b.c
Correct Answer: (B)
[EN] extern tells b.c not to allocate new storage, letting the linker bind 'score' to a.o's single external definition.
[HI] b.c में 'extern int score;' लिखने से नई मेमोरी नहीं बनती, बल्कि लिंकर इसे a.c के score से जोड़ देता है।
Q14. What scope applies to the variable 'i' in C99/C11: for (int i = 0; i < 5; i++) { ... }?
(C99/C11 में 'for (int i = 0; i < 5; i++) { ... }' के भीतर घोषित वेरिएबल 'i' का स्कोप कहाँ तक होता है?)
(A) Function scope across all of main()
(B) Block scope limited strictly to the for-loop header and body
(C) File scope across the entire .c file
(D) Not allowed in C99 (valid only in C++)
Correct Answer: (B)
[EN] C99 introduced loop-header declarations whose scope ends as soon as the for loop completes.
[HI] C99 ने for-लूप के भीतर वेरिएबल डिक्लेरेशन की सुविधा दी, जिसका स्कोप केवल उस लूप ब्लॉक तक ही सीमित रहता है।
Q15. What is the scope of parameter names 'rows' and 'cols' inside a prototype: void print_grid(int rows, int cols);
(फंक्शन प्रोटोटाइप 'void print_grid(int rows, int cols);' में 'rows' और 'cols' नामों का स्कोप क्या होता है?)
(A) Block scope across the whole file
(B) Global external linkage
(C) Function Prototype scope (ends immediately at the closing parenthesis ')')
(D) Static lifetime
Correct Answer: (C)
[EN] Parameter identifiers inside a prototype are purely for documentation and vanish right at ')'.
[HI] फंक्शन प्रोटोटाइप के कोष्ठक में लिखे पैरामीटर नामों का स्कोप ठीक अंतिम ')' पर समाप्त हो जाता है।
Q16. Which statement about Variables and Scope in C is FALSE?
(C में वेरिएबल्स और स्कोप के बारे में निम्नलिखित में से कौन सा कथन असत्य (FALSE) है?)
(A) Declaring a variable inside an inner { } block with the same name as a global variable permanently overwrites the global variable's value
(B) Uninitialized static local variables default to zero
(C) Automatic local variables lose their values when their function returns
(D) Global variables without static have external linkage by default
Correct Answer: (A)
[EN] Shadowing only hides the outer global identifier inside the inner block; the global variable's memory location remains untouched.
[HI] शैडोइंग बाहरी ग्लोबल वेरिएबल के मान को नष्ट नहीं करती, बल्कि केवल उस अंदरूनी ब्लॉक के भीतर नाम को अस्थायी रूप से छिपाती है।
Q17. Within Variables: Declaration, Initialization and Scope in C, which storage class directly maps to: "Call Stack; Indeterminate (Garbage) value"?
(Variables: Declaration, Initialization and Scope in C में कौन सा Storage Class सीधे "Call Stack; Indeterminate (Garbage) value" से संबंधित है?)
(A) extern
(B) auto (Default Local)
(C) static
(D) register
Correct Answer: (B)
[EN] In Variables: Declaration, Initialization and Scope in C, 'auto (Default Local)' handles 'Call Stack; Indeterminate (Garbage) value' (Block scope; function-call lifetime; No linkage).
[HI] Variables: Declaration, Initialization and Scope in C में 'auto (Default Local)' का कार्य/विवरण 'Call Stack; Indeterminate (Garbage) value' (Block scope; function-call lifetime; No linkage) है।
Q18. Which option accurately describes 'register' in Variables: Declaration, Initialization and Scope in C?
(Variables: Declaration, Initialization and Scope in C के संदर्भ में 'register' की सही विशेषता कौन सी है?)
(A) CPU Register hint; Indeterminate value
(B) .data / .bss (defined in another unit); Zero (0)
(C) .data / .bss segment; Zero (0 / NULL)
(D) Call Stack; Indeterminate (Garbage) value
Correct Answer: (A)
[EN] 'register' provides 'CPU Register hint; Indeterminate value' — key point: Block scope; address-of (&var) is ILLEGAL in C.
[HI] 'register' का मुख्य विवरण 'CPU Register hint; Indeterminate value' है (Block scope; address-of (&var) is ILLEGAL in C)।
Q19. In Variables: Declaration, Initialization and Scope in C, identify the correct parameter for the specification: ".data / .bss segment; Zero (0 / NULL)".
(Variables: Declaration, Initialization and Scope in C में ".data / .bss segment; Zero (0 / NULL)" विवरण किस विकल्प के लिए सही है?)
(A) auto (Default Local)
(B) extern
(C) static
(D) register
Correct Answer: (C)
[EN] 'static' corresponds to '.data / .bss segment; Zero (0 / NULL)' (Program lifetime; Local=Block scope, Global=Internal linkage).
[HI] 'static' का संबंध '.data / .bss segment; Zero (0 / NULL)' (Program lifetime; Local=Block scope, Global=Internal linkage) से है।
Q20. Considering Variables: Declaration, Initialization and Scope in C, what key behavior defines 'extern'?
(Variables: Declaration, Initialization and Scope in C में 'extern' की मुख्य भूमिका या मान क्या है?)
(A) .data / .bss segment; Zero (0 / NULL)
(B) Call Stack; Indeterminate (Garbage) value
(C) .data / .bss (defined in another unit); Zero (0)
(D) CPU Register hint; Indeterminate value
Correct Answer: (C)
[EN] 'extern' represents '.data / .bss (defined in another unit); Zero (0)' (File/Block scope; Program lifetime; External linkage).
[HI] 'extern' का अर्थ/मान '.data / .bss (defined in another unit); Zero (0)' है (File/Block scope; Program lifetime; External linkage)।
Variables: Declaration, Initialization and Scope in C — Exam FAQs
Q1: What is the exact difference between Declaration and Definition of a variable in C?
C में किसी वेरिएबल के Declaration और Definition में सटीक अंतर क्या है?
[EN] Declaration ('extern int x;') informs the compiler of the variable's name and type without reserving RAM, so it can appear many times (e.g., in headers). Definition ('int x;' or 'int x = 5;') actually allocates memory storage and can exist only once for external symbols.
[HI] Declaration ('extern int x;') बिना मेमोरी बनाए कंपाइलर को नाम व टाइप बताता है, जबकि Definition ('int x;') वास्तविक RAM आवंटित करती है और बाहरी सिंबल के लिए केवल एक बार हो सकती है।
Q2: How does 'static' mean two different things for local vs global variables in C?
C में 'static' कीवर्ड का लोकल वेरिएबल बनाम ग्लोबल वेरिएबल पर अलग-अलग अर्थ क्यों होता है?
[EN] On a local variable, static changes its LIFETIME from automatic (stack) to static (persists across calls) while keeping block scope. On a global variable or function (already static lifetime), static changes its LINKAGE from external to internal (private to that .c file).
[HI] लोकल वेरिएबल पर static उसका जीवनकाल (Lifetime) बढ़ाकर कॉल के बीच मान सुरक्षित रखता है, जबकि ग्लोबल वेरिएबल/फंक्शन पर यह उसकी लिंकेज को एक्सटर्नल से बदलकर इंटरनल (केवल उसी फाइल तक सीमित) कर देता है।
Q3: Why is taking the address of a 'register' variable disallowed in C?
C में 'register' वेरिएबल का एड्रेस (&) लेना क्यों मना है?
[EN] Because register requests placing the variable directly inside a CPU hardware register rather than addressable RAM—and CPU registers have no memory addresses. (Note: C++ later allowed ®ister by quietly ignoring the register hint.)
[HI] क्योंकि register वेरिएबल को RAM के बजाय सीधे CPU रजिस्टर में रखने का सुझाव देता है और CPU रजिस्टर का कोई RAM मेमोरी एड्रेस नहीं होता।
Post a Comment
Post a Comment