FliQi Education App Download
प्रश्न-बैंक · C Language

Storage Classes in C Language — प्रश्न और उत्तर

C Language · 90 जाँचे हुए (verified) प्रश्न

  • 90 जाँचे हुए प्रश्न
  • हिंदी + English

पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।

भाषा
प्रश्न 1उत्तर + हल
निम्नलिखित कोड का आउटपुट क्या होगा?

#include<stdio.h>

int main()

{

extern int var;

printf("The value of var is %d", var);

return 0;

}
What will be the output of the following code?

#include<stdio.h>

int main()

{

extern int var;

printf("The value of var is %d", var);

return 0;

}
  1. A0
  2. Bगार्बेजgarbage
  3. Cकोई आउटपुट नहींNo output
  4. Dलिंकिंग एररLinking error

सही उत्तर / Answer: (D)

हल / Solution
extern वाली पंक्ति सिर्फ़ घोषणा है, परिभाषा नहीं — वह compiler से कहती है कि var कहीं और बना हुआ है। पूरे प्रोग्राम में var की परिभाषा कहीं दी ही नहीं गई, इसलिए संकलन तो हो जाता है पर जोड़ते समय लिंकर को वह चिह्न मिलता ही नहीं। तब «undefined reference» जैसी लिंकिंग एरर आती है। चूँकि प्रोग्राम चल ही नहीं पाता, शून्य या गार्बेज छपने का सवाल नहीं उठता।
The extern line is only a declaration and not a definition; it tells the compiler that var is created somewhere else. Nowhere in the program is var actually defined, so compilation succeeds but the linker cannot find that symbol while joining the object files. It then reports an undefined reference, which is a linking error. Since the program never runs, neither zero nor garbage can ever be printed.
प्रश्न 2उत्तर + हल
मान लीजिए किसी वेरिएबल को register स्टोरेज क्लास के साथ घोषित किया गया है, पर कोई रजिस्टर ख़ाली नहीं है, तब:
Suppose a variable is declared with register storage class but no register is free then:
  1. Aडेटा नष्ट हो जाता हैData loss
  2. Bकम्पाइलेशन एररCompilation error
  3. Cवह मुख्य मेमोरी में जगह लेता हैIt will occupy main memory
  4. Dइनमें से कोई नहींNone of these

सही उत्तर / Answer: (C)

हल / Solution
register लिखना compiler से सिर्फ़ अनुरोध है, आदेश नहीं। अगर उस वक़्त कोई रजिस्टर ख़ाली न हो, तो compiler चुपचाप उस चर को साधारण चर की तरह मुख्य मेमोरी में रख देता है और प्रोग्राम ठीक चलता रहता है। न कोई मान खोता है, न कोई त्रुटि आती है। इसी वजह से register चर का पता लेना मना है, क्योंकि वह रजिस्टर में भी हो सकता है। सो सही उत्तर मुख्य मेमोरी वाला विकल्प है।
Writing register is only a request to the compiler and not a command. If no register happens to be free at that moment, the compiler quietly keeps the variable in main memory like an ordinary one, and the program still runs correctly. No value is lost and no error is reported. This is also why taking the address of a register variable is forbidden, since it may really sit inside a register. So the third choice is right.
प्रश्न 3उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?

#include<stdio.h>

void main(){

inc();

inc();

inc();

}

inc(){

static int x;

printf("%d", ++x);

}
What does the following program print?

#include<stdio.h>

void main(){

inc();

inc();

inc();

}

inc(){

static int x;

printf("%d", ++x);

}
  1. A123 छापता हैprints 123
  2. B111 छापता हैprints 111
  3. C012 छापता हैprints 012
  4. Dतीन क्रमागत, पर अनिश्चित संख्याएँ छापता हैprints 3 consecutive, but unpredictable numbers

सही उत्तर / Answer: (A)

हल / Solution
फ़ंक्शन inc के भीतर x स्थायी (static) है, इसलिए वह एक ही बार बनता है और हर कॉल के बीच अपना मान सँभाले रखता है। बिना आरंभिक मान वाला static चर शून्य से शुरू होता है। पहली कॉल में ++x पहले बढ़ाता है, सो एक छपता है; दूसरी में दो और तीसरी में तीन। इसलिए लगातार 123 छपता है। मान हर बार शून्य से शुरू होता तो 111 आता, और संख्याएँ अनिश्चित कभी नहीं होतीं।
Inside the function inc the variable x is static, so it is created only once and keeps its value between calls. A static variable with no initial value starts at zero. On the first call ++x increments first, so one is printed; the second call prints two and the third prints three. The program therefore prints 123. Starting afresh each time would have given 111, and the numbers are never unpredictable.
प्रश्न 4उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या है?

#include<stdio.h>

int tmp=20;

main( ){

printf("%d ",tmp);

func( );

printf("%d ",tmp);

}

func( ){

static int tmp=10;

printf("%d ",tmp);

}
What is the output of the following program?

#include<stdio.h>

int tmp=20;

main( ){

printf("%d ",tmp);

func( );

printf("%d ",tmp);

}

func( ){

static int tmp=10;

printf("%d ",tmp);

}
  1. A10 10 10
  2. B20 20 20
  3. C20 10 20
  4. D20 10 10

सही उत्तर / Answer: (C)

हल / Solution
बाहर घोषित tmp वैश्विक चर है जिसका मान बीस है। पहला printf main में चलता है, जहाँ वही चर दिखता है, सो बीस छपता है। func के भीतर अलग static tmp है जिसका मान दस है, और वह उसी फ़ंक्शन में वैश्विक वाले को ढक देता है, इसलिए दस छपता है। func से लौटने पर छाया हट जाती है और तीसरा printf फिर वैश्विक tmp पढ़ता है, सो दोबारा बीस आता है।
The tmp declared outside is a global variable holding twenty. The first printf runs in main, where that variable is visible, so it prints twenty. Inside func there is a separate static tmp holding ten, which hides the global one within that function, so ten is printed next. After func returns the shadow is gone and the third printf reads the global tmp again, printing twenty once more.
प्रश्न 5उत्तर + हल
नीचे लिखे कोड में वेरिएबल i का स्टोरेज क्लास क्या होगा?

#include< stdio.h>

int main()

{

int i = 10;

printf("%d", i);

return 0;

}
What will be the storage class of variable i in the following code?

#include< stdio.h>

int main()

{

int i = 10;

printf("%d", i);

return 0;

}
  1. Aस्टैटिक स्टोरेज क्लासStatic storage class
  2. Bरजिस्टर स्टोरेज क्लासRegister storage class
  3. Cऑटोमैटिक स्टोरेज क्लासAutomatic storage class
  4. Dएक्सटर्न स्टोरेज क्लासExtern storage class

सही उत्तर / Answer: (C)

हल / Solution
i फ़ंक्शन main के भीतर बिना किसी कीवर्ड के घोषित है। ऐसे चर का भंडारण वर्ग अपने-आप auto यानी ऑटोमैटिक मान लिया जाता है। वह स्टैक पर बनता है, फ़ंक्शन ख़त्म होते ही मिट जाता है और उसकी पहुँच उसी खंड तक रहती है। static या register पाने के लिए वही शब्द लिखना पड़ता, और extern तो दूसरी फ़ाइल के चर से जोड़ता है। इसलिए उत्तर ऑटोमैटिक स्टोरेज क्लास है।
Here i is declared inside the function main without any keyword. The storage class of such a variable is taken to be auto, that is automatic, by default. It is created on the stack, dies as soon as the function ends, and is visible only inside that block. To get static or register you would have to write the word itself, and extern would link the name to a variable defined in another file.
प्रश्न 6उत्तर + हल
स्टोरेज-क्लास विनिर्देशक के साथ फ़ंक्शन परिभाषा के लिए निम्नलिखित में से कौन-सा सही है?
Which of the following is correct for a function definition with a storage-class specifier?
  1. Aint fun (register int arg)
  2. Bint fun(static int args)
  3. Cint fun(auto int arg)
  4. Dउपरोक्त सभी सही हैं।All of the above are correct.

सही उत्तर / Answer: (A)

हल / Solution
फ़ंक्शन के प्राचल (parameter) पर C सिर्फ़ एक ही भंडारण वर्ग लगने देता है, और वह register है। इसलिए पहला रूप वैध परिभाषा है। static लगाने पर त्रुटि आती है, क्योंकि प्राचल हर कॉल पर नया बनता है और उसे टिकाया नहीं जा सकता। auto भी प्राचल पर लिखना मना है, जबकि फ़ंक्शन के भीतर वह चलता है। चूँकि दो रूप ग़लत हैं, उपरोक्त सभी वाला विकल्प भी ग़लत हो जाता है।
For a function parameter C allows only one storage class specifier, and that is register. So the first form is a valid definition. Writing static there is an error, because a parameter is created afresh on every call and cannot be made to persist. Writing auto on a parameter is also not allowed, although it is accepted inside the body of a function. Since two forms are wrong, the last choice fails too.
प्रश्न 7उत्तर + हल
सही कथन का चयन कीजिए।
Select the correct statement
  1. Aस्टैटिक प्रकार के वेरिएबल तब ही इनिशियलाइज़ होते हैं जब ब्लॉक या फ़ंक्शन पहली बार कॉल होता है।Variables of type static are initialized only the first time the block or function is called
  2. Bरजिस्टर प्रकार के वेरिएबल हर बार ब्लॉक या फ़ंक्शन चलने पर इनिशियलाइज़ होते हैं।The variables of the type register are initialized each time the block or function is executed
  3. Cऑटो प्रकार के वेरिएबल हर ब्लॉक या फ़ंक्शन कॉल पर नए सिरे से इनिशियलाइज़ होते हैं।Variables of type auto are initialized fresh for each block or function call
  4. Dउपरोक्त सभी।All of the above

सही उत्तर / Answer: (D)

हल / Solution
static चर पूरे चलन में एक ही बार बनता है, सो उसका आरंभिक मान पहली बार ही बैठता है और अगली कॉल में पुराना मान बचा रहता है। register और auto दोनों स्थानीय चर हैं, जो हर कॉल पर नए सिरे से बनते हैं, इसलिए उनका आरंभीकरण हर बार दोहराया जाता है। तीनों कथन इसी बरताव को ठीक-ठीक बताते हैं और कोई दूसरे को काटता नहीं। इसलिए सही उत्तर उपरोक्त सभी है।
A static variable is created only once for the whole run, so its initial value is set the first time and the old value survives into the next call. Both register and auto are local variables that are created afresh on every call, so their initialisation is repeated each time. All three statements describe exactly this behaviour and none of them contradicts another, so all of the above is right.
प्रश्न 8उत्तर + हल
एक सही कथन चुनिए।
Select one correct statement
  1. Aस्टैटिक प्रकार के वेरिएबल सेगमेंटेड मेमोरी में स्टोर किए जाते हैं।Variables of type static are stored in segmented memory
  2. Bरजिस्टर प्रकार के वेरिएबल माइक्रोप्रोसेसर की मेमोरी में स्टोर किए जाते हैं।The variables of the type register are stored in the microprocessor memory
  3. Cऑटो प्रकार के वेरिएबल स्टैक मेमोरी में स्टोर किए जाते हैं।Variables of auto type are stored in the stack memory
  4. Dउपरोक्त सभी।All of the above

सही उत्तर / Answer: (D)

हल / Solution
तीनों कथन अपनी जगह ठीक हैं। static चर पूरे चलन तक जीवित रहते हैं, इसलिए वे स्टैक पर नहीं, अलग डेटा खंड में रखे जाते हैं। register लगाने पर compiler चर को माइक्रोप्रोसेसर के रजिस्टर में रखने की कोशिश करता है, ताकि पहुँच तेज़ हो। auto चर फ़ंक्शन के साथ बनते और मिटते हैं, सो उनकी जगह स्टैक होती है। चूँकि कोई कथन ग़लत नहीं है, उत्तर उपरोक्त सभी है।
All three statements hold. Static variables stay alive for the whole run of the program, so they are kept in a separate data segment rather than on the stack. Writing register asks the compiler to keep the variable in a microprocessor register so that access becomes faster. Auto variables are created and destroyed with the function call, so their home is the stack. Since none of them is wrong, all of the above is correct.
प्रश्न 9उत्तर + हल
लोकल और ग्लोबल वेरिएबल के नामों में टकराव होने पर क्या होता है?
What happens in case of conflict between the names of local and global variables?
  1. Aलोकल वेरिएबल को प्राथमिकता दी जाती है।Local variables are preferred
  2. Bग्लोबल वेरिएबल को प्राथमिकता दी जाती है।Global variables are preferred
  3. Cकिसे प्राथमिकता मिलेगी यह इस पर निर्भर है कि किसे पहले परिभाषित किया गया है।Which one will get priority depends on which one is defined first
  4. Dकम्पाइलर एक त्रुटि की रिपोर्ट करता है।compiler reports an error

सही उत्तर / Answer: (A)

हल / Solution
नाम ढूँढ़ते समय compiler सबसे भीतरी क्षेत्र (scope) से शुरू करता है, इसलिए फ़ंक्शन के भीतर वाला चर उसी नाम के वैश्विक चर को ढक देता है। इसे छाया पड़ना (shadowing) कहते हैं। वैश्विक चर मिटता नहीं, उस खंड से बाहर आते ही वह फिर दिखने लगता है। यह नियम भाषा में तय है, सो किसे पहले लिखा गया इससे कुछ नहीं बदलता, और ऐसा टकराव त्रुटि भी नहीं है।
While looking a name up, the compiler starts from the innermost scope, so a variable inside a function hides the global variable of the same name. This is called shadowing. The global variable is not destroyed; it becomes visible again as soon as we leave that block. The rule is fixed by the language, so the order of definition changes nothing, and such a clash is not an error at all.
प्रश्न 10उत्तर + हल
C में कितने स्टोरेज क्लास होते हैं?
How many storage classes are there in C ?
  1. A2
  2. B3
  3. C4
  4. D5

सही उत्तर / Answer: (C)

हल / Solution
C में चार भंडारण वर्ग (storage classes) हैं — auto, register, static और extern। हर एक यह तय करता है कि चर कहाँ रखा जाएगा, कब तक जीवित रहेगा और कहाँ से दिखेगा। फ़ंक्शन के भीतर बिना कुछ लिखे बना चर auto होता है, register उसे तेज़ पहुँच के लिए सुझाता है, static उसे पूरे चलन तक जिलाए रखता है और extern दूसरी फ़ाइल के चर से जोड़ता है। इसलिए सही उत्तर चार है।
C has four storage classes, namely auto, register, static and extern. Each of them decides where a variable is kept, how long it lives and from where it can be seen. A variable written inside a function without any keyword is auto, register asks for faster access, static keeps it alive for the whole run of the program, and extern links it to a variable defined in another file. So the answer is four.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
App खोलिए
प्रश्न 13उत्तर app में
एक रजिस्टर वेरिएबल एक रजिस्टर में संग्रहीत होता है। कंप्यूटर में रजिस्टर कहाँ मौजूद होता है?
A register variable is stored in a Register. Where is a Register present in a Computer?
  1. ACPU (सेंट्रल प्रोसेसिंग यूनिट)CPU (Central Processing Unit)
  2. BDMA (डायरेक्ट मेमोरी एक्सेस)DMA (Direct Memory Access)
  3. CRAM (रैंडम एक्सेस मेमोरी)RAM (Random Access Memory)
  4. DROM (रीड ओनली मेमोरी)ROM (Read Only Memory)
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 17उत्तर app में
हर C वेरिएबल में क्या होना चाहिए?
Every C Variable must have?
  1. Aस्टोरेज क्लासStorage Class
  2. Bडेटा टाइपData Type
  3. Cडेटा टाइप और स्टोरेज क्लास दोनोंBoth Data Type and Storage Class
  4. Dडेटा टाइप या स्टोरेज क्लास में से कोई एकEither Type or Storage Class
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 18उत्तर app में
C स्टोरेज क्लास क्या है?
What is a C Storage Class?
  1. AC स्टोरेज क्लास तय करती है कि एक वेरिएबल का डिफ़ॉल्ट मान क्या हैC Storage Class decides what is the default value of a variable
  2. BC स्टोरेज क्लास तय करती है कि वेरिएबल का स्कोप और लाइफ क्या हैC Storage Class decides what is the Scope and Life of a variable
  3. CC स्टोरेज क्लास यह तय करती है कि वेरिएबल को कहाँ या किस मेमोरी में स्टोर करना हैC Storage decides where to or which memory store the variable
  4. Dउपरोक्त सभीAll the above
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 19उत्तर app में
यदि 'C' भाषा में किसी वेरिएबल की स्टोरेज क्लास को 'रजिस्टर' के रूप में निर्दिष्ट किया जाता है, तो निम्नलिखित में से कौन सा ऑपरेटर उस पर लागू नहीं किया जा सकता है?
If the storage class of a variable in 'C' is specified as 'register', which of the following operators cannot be applied to it?
  1. A!
  2. B--
  3. C&
  4. D++
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 20उत्तर app में
निम्नलिखित सूची का मिलान कीजिए:

(a) auto      (i) register, garbage,local

(b) register (ii) RAM, zero, global

(c) static      (iii)  RAM, garbage, local

(d) extern   (iv) RAM, zero, local
Match the following list:

(a) auto      (i) register, garbage,local

(b) register (ii) RAM, zero, global

(c) static      (iii)  RAM, garbage, local

(d) extern   (iv) RAM, zero, local
  1. A(a) – (iv), (b) – (ii), (c) – (iii), (d) – (i)
  2. B(a) – (i), (b) – (iv), (c) – (ii), (d) – (iii)
  3. C(a) – (ii), (b) – (iii), (c) – (i), (d) – (iv)
  4. D(a) – (iii), (b) – (i), (c) – (iv), (d) – (ii)
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 22उत्तर app में
'C' प्रोग्राम में स्टैटिक वेरिएबल का जीवनकाल (दीर्घायु) है:
The lifetime (longevity) of a static variable in a 'C' program is:
  1. Aपहले प्रोग्राम के अंत तकBy the end of the first program
  2. Bमेन (main) प्रोग्राम के अंत तकuntil the end of the main program
  3. Cजब तक पहले दस स्टेटमेंट्स का एक्ज़िक्यूशन नहीं हो जाताuntil the first ten statements are executed
  4. Dउस फ़ंक्शन के भीतर जिसमें वे परिभाषित हैंWithin the function in which they are defined
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 25उत्तर app में
ऑटोमैटिक वेरिएबल्स को ___________ से इनिशियलाइज़ किया जाता है।
Automatic variables are initialized to ___________
  1. Aशून्यZero
  2. Bजंक मानJunk value
  3. Cकुछ नहींNothing
  4. Dशून्य और जंक मान दोनोंBoth Zero & Junk value
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 26उत्तर app में
निम्नलिखित C कोड में x क्या होगा?

#include <stdio.h>

    void main()

    {

        int x;

    }
What will be the x in the following C code?

#include <stdio.h>

    void main()

    {

        int x;

    }
  1. Aautomatic वेरिएबलautomatic variable
  2. Bstatic वेरिएबलstatic variable
  3. Cregister वेरिएबलregister variable
  4. Dglobal वेरिएबलglobal variable
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 29उत्तर app में
निम्नलिखित C कोड का आउटपुट क्या होगा?

#include <stdio.h>

    void foo(auto int i);

    int main()

    {

        foo(10);

    }

    void foo(auto int i)

    {

        printf("%d\n", i );

    }
What will be the output of the following C code?

#include <stdio.h>

    void foo(auto int i);

    int main()

    {

        foo(10);

    }

    void foo(auto int i)

    {

        printf("%d\n", i );

    }
  1. A10
  2. Bकंपाइल टाइम एररCompile time error
  3. Cमानक (standard) पर निर्भर करता हैDepends on the standard
  4. Dइनमें से कोई नहींNone of the mentioned
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
प्रश्न 30उत्तर app में
यदि किसी लोकल वेरिएबल के लिए स्टोरेज क्लास निर्दिष्ट नहीं है, तो डिफ़ॉल्ट क्लास auto होगी।
If storage class is not specified for a local variable, then the default class will be auto.
  1. Aसत्यTrue
  2. Bअसत्यFalse
  3. Cमानक (standard) पर निर्भर करता हैDepends on the standard
  4. Dइनमें से कोई नहींNone of the mentioned
उत्तर और हल FliQi Question Bank app में देखें (Answer & solution in the app)
Storage Classes in C Language के सभी 90 प्रश्न — उत्तर, हल और अभ्यास

FliQi Question Bank app में topic-वार अभ्यास, कठिनाई-स्तर और आपकी प्रगति।

  • पहला test मुफ़्त
  • हिंदी + English
  • जाँचे हुए उत्तर और हल

यह topic किन परीक्षाओं में आता है

C Language के दूसरे topics

सभी topics