void का अर्थ है 'कोई type नहीं'। void प्रकार का variable नहीं बनाया जा सकता, क्योंकि उसका कोई आकार नहीं होता और उसमें कोई मान नहीं रखा जा सकता। इसलिए void num=10; पर compiler error देता है। साथ ही %v कोई मान्य format specifier भी नहीं है। program compile ही नहीं होता, इसलिए 10, garbage या 0 कुछ नहीं छपता। सही उत्तर Compilation error है।
void means no type. A variable of type void cannot be created, because it has no size and cannot hold any value. So the compiler reports an error at void num=10;. Also, %v is not a valid format specifier. The program does not compile, so 10, a garbage value or 0 is never printed. The answer is Compilation error.
प्रश्न 2उत्तर + हल
निम्नलिखित कोड स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
void main()
{
int a=1, b=2, c=3, d;
d = (a=c, b+=a, c=a+b+c);
printf("%d %d %d %d", d, a, b, c);
}
What will be the output of the following code snippet?
#include <stdio.h>
void main()
{
int a=1, b=2, c=3, d;
d = (a=c, b+=a, c=a+b+c);
printf("%d %d %d %d", d, a, b, c);
}
A11 3 5 11
B11 1 5 11
C11 3 2 11
D11 3 3 11
सही उत्तर / Answer: (A)
हल / Solution
comma operator हर भाग को बाएँ से दाएँ हल करता है और आख़िरी भाग का मान देता है। शुरू में a = 1, b = 2, c = 3। a = c से a = 3। b += a से b = 5। c = a + b + c से c = 3 + 5 + 3 = 11। आख़िरी मान 11 है, इसलिए d = 11। बाक़ी विकल्पों में a या b का पुराना मान है।
The comma operator evaluates parts left to right and gives the value of the last part. At the start a = 1, b = 2, c = 3. a = c makes a = 3. b += a makes b = 5. c = a + b + c makes c = 3 + 5 + 3 = 11. The last value is 11, so d = 11. The other options keep an old value of a or b.
प्रश्न 3उत्तर + हल
निम्नलिखित कोड स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main() {
int c = - -14;
printf("%d", c);
return 0;
}
What will be the output of the following code snippet?
#include <stdio.h>
int main() {
int c = - -14;
printf("%d", c);
return 0;
}
A13
B14
C-14
DCompile Time Error
सही उत्तर / Answer: (B)
हल / Solution
int c = - -14; में दोनों minus चिह्नों के बीच space है। इसलिए ये -- (decrement) operator नहीं बनते, बल्कि दो अलग unary minus हैं। यानी c = -(-14)। ऋण का ऋण धन होता है, इसलिए c = 14 और 14 छपता है। -14 तब आता जब एक ही minus होता। 13 decrement की ग़लत सोच से बनता है। यह वैध syntax है, इसलिए कोई error नहीं।
In int c = - -14; there is a space between the two minus signs. So they do not form the -- (decrement) operator; they are two separate unary minus signs. That means c = -(-14). The negative of a negative is positive, so c = 14 and 14 is printed. -14 would need a single minus. 13 comes from wrongly thinking of decrement. The syntax is valid, so there is no error.
प्रश्न 4उत्तर + हल
निम्नलिखित कोड स्निपेट के अनुसार कौन सा ऑपरेशन पहले होगा?
#include <stdio.h>
int main() {
int num = num;
printf("%d ", num);
return 0;
}
Which operation will perform first as per the following code snippet?
int num = num; में पहले num की घोषणा होती है। C में variable का scope उसके नाम के ठीक बाद शुरू हो जाता है, यानी = से पहले ही। इसलिए दाईं ओर वाला num भी यही नया variable है। घोषणा के बाद ही उसे मान दिया जाता है। पर उस समय num में कोई तय मान नहीं होता, इसलिए garbage छप सकता है। यह कोड compile और run दोनों होता है, कोई error नहीं।
In int num = num; the declaration of num happens first. In C a variable's scope starts right after its name, before the = sign. So the num on the right side is this same new variable. Only after the declaration is it given a value. But at that moment num holds no fixed value, so a garbage number may be printed. The code compiles and runs without any error.
प्रश्न 5उत्तर + हल
नीचे दिए गए प्रोग्राम से क्या परिणाम प्राप्त होगा?
#include<stdio.h>
void main()
{
int x = 10;
char x = ‘A’;
printf("%d", x)
}
What would be the output obtained out of the program mentioned below?
#include<stdio.h>
void main()
{
int x = 10;
char x = ‘A’;
printf("%d", x)
}
A10
BA
C65
DCompile Time Error
सही उत्तर / Answer: (D)
हल / Solution
एक ही scope में एक नाम से दो variable नहीं बन सकते। यहाँ पहले int x = 10; है और फिर उसी block में char x घोषित है। compiler इसे x की दोबारा परिभाषा मानकर error देता है। साथ ही printf वाली पंक्ति के अंत में semicolon (;) भी नहीं है, वह भी error है। program compile नहीं होता, इसलिए 10, A या 65 कुछ नहीं छपता।
Two variables with the same name cannot exist in the same scope. Here int x = 10; comes first, and then char x is declared in the same block. The compiler treats this as a redefinition of x and reports an error. The printf line is also missing its semicolon, which is another error. The program does not compile, so 10, A or 65 is never printed.
प्रश्न 6उत्तर + हल
नीचे दिए गए प्रोग्राम से क्या परिणाम प्राप्त होगा?
#include <stdio.h>
int main()
{
int v= 12,13,14;
int z;
z= (12,13,14);
printf(“v= %d, z= %d\n”,v,z);
return 0;
}
What would be the output obtained out of the program mentioned below?
#include <stdio.h>
int main()
{
int v= 12,13,14;
int z;
z= (12,13,14);
printf(“v= %d, z= %d\n”,v,z);
return 0;
}
Av= 13, z= 14
Bv= 12, z=13
Cv= 12, z= 14
DCompile-time Error
सही उत्तर / Answer: (D)
हल / Solution
घोषणा में comma, comma operator नहीं होता, वह सिर्फ़ अलग-अलग variable नामों को अलग करता है। int v= 12,13,14; में v = 12 के बाद compiler अगला variable नाम ढूँढता है, पर उसे 13 मिलता है। इसलिए यहीं compile error आती है। अगर यह पंक्ति ठीक होती, तो z = (12,13,14) से z = 14 मिलता। printf के टेढ़े quotes भी error देते। इसलिए कोई आउटपुट नहीं छपता।
In a declaration the comma is not the comma operator; it only separates variable names. In int v= 12,13,14; after v = 12 the compiler expects another variable name but finds 13. So a compile error occurs right here. If this line were fine, z = (12,13,14) would give z = 14. The curly quotes in printf would also cause an error. So no output is printed.
प्रश्न 7उत्तर + हल
निम्नलिखित कोड स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main() {
int scanf = 10;
int a;
scanf("%d",&a);
scanf = a;
printf("%d",scanf);
return 0;
}
What will be the output of the following code snippet?
#include <stdio.h>
int main() {
int scanf = 10;
int a;
scanf("%d",&a);
scanf = a;
printf("%d",scanf);
return 0;
}
A10
Bवेरिएबल a में डाले गए मान पर निर्भरDepends on the inputted value of variable a
CGarbage Value (कचरा मान)Garbage Value
DCompile Time Error
सही उत्तर / Answer: (D)
हल / Solution
int scanf = 10; से main के अंदर scanf एक int variable बन जाता है। यह library वाले scanf function को छिपा देता है। अगली पंक्ति scanf("%d",&a); इस int को function की तरह बुलाती है। int को call नहीं किया जा सकता, इसलिए compiler error देता है कि called object function नहीं है। program चलता ही नहीं, इसलिए 10, input वाला मान या garbage कुछ नहीं छपता।
int scanf = 10; turns scanf into an int variable inside main. It hides the library scanf function. The next line, scanf("%d",&a);, tries to call this int like a function. An int cannot be called, so the compiler reports that the called object is not a function. The program never runs, so nothing is printed: not 10, not the input value and not garbage.
प्रश्न 8उत्तर + हल
निम्नलिखित कोड स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main() {
int scanf = 10;
printf("%d",scanf);
return 0;
}
What will be the output of the following code snippet?
#include <stdio.h>
int main() {
int scanf = 10;
printf("%d",scanf);
return 0;
}
A10
B0
CGarbage Value (कचरा मान)Garbage Value
DCompile Time Error
सही उत्तर / Answer: (A)
हल / Solution
scanf कोई keyword नहीं है, यह stdio.h में घोषित एक library function का नाम है। main के अंदर int scanf = 10; से scanf नाम का local variable बनता है, जो उस block में function वाले नाम को छिपा देता है। printf इसी variable का मान छापता है, इसलिए 10 आता है। variable को मान दिया गया है, इसलिए 0 या garbage नहीं। compile error भी नहीं आती।
scanf is not a keyword; it is the name of a library function declared in stdio.h. Inside main, int scanf = 10; creates a local variable named scanf, which hides the function name in that block. printf prints the value of this variable, so the output is 10. The variable is initialized, so the answer is not 0 or garbage. There is no compile error either.
प्रश्न 9उत्तर + हल
निम्नलिखित कोड स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main() {
int a = 20;
a+30 = a;
printf("%d",a);
return 0;
}
What will be the output of the following code snippet?
#include <stdio.h>
int main() {
int a = 20;
a+30 = a;
printf("%d",a);
return 0;
}
A20
B30
C50
DCompile Time Error
सही उत्तर / Answer: (D)
हल / Solution
a + 30 = a; में = के बाईं ओर a + 30 है। यह एक expression है जिसका नतीजा सिर्फ़ एक अस्थायी मान है। उसकी मेमोरी में कोई जगह नहीं होती, इसलिए उसमें मान रखा नहीं जा सकता। = के बाईं ओर हमेशा variable (lvalue) चाहिए। इसलिए compiler error देता है। program चलता ही नहीं, इसलिए 20, 30 या 50 जैसा कोई आउटपुट नहीं आता।
In a + 30 = a; the left side of = is a + 30. This is an expression whose result is only a temporary value. It has no memory location, so nothing can be stored in it. The left side of = must always be a variable (an lvalue). So the compiler reports an error. The program never runs, so no output such as 20, 30 or 50 appears.
प्रश्न 10उत्तर + हल
निम्नलिखित कोड स्निपेट का आउटपुट क्या होगा?
#include <stdio.h>
int main() {
int a = 20;
30 = a;
a = a+30;
printf("%d",a);
return 0;
}
What will be the output of the following code snippet?
#include <stdio.h>
int main() {
int a = 20;
30 = a;
a = a+30;
printf("%d",a);
return 0;
}
A20
B30
C60
DCompile Time Error
सही उत्तर / Answer: (D)
हल / Solution
कथन 30 = a; में = के बाईं ओर 30 लिखा है। 30 एक constant है, इसकी मेमोरी में कोई जगह नहीं जहाँ मान रखा जाए। = के बाईं ओर हमेशा variable (lvalue) होना चाहिए। इसलिए compiler इसी पंक्ति पर error देता है। सही रूप a = 30; होता। program compile ही नहीं होता, इसलिए 20, 30 या 60 जैसा कोई आउटपुट नहीं आता।
In the statement 30 = a; the left side of = is 30. 30 is a constant; it has no memory location where a value can be stored. The left side of = must always be a variable (an lvalue). So the compiler gives an error at this line. The correct form would be a = 30;. The program does not compile, so no output such as 20, 30 or 60 appears.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
Which statement is false about the global variable?
Aएक वेरिएबल जिसे फंक्शन ब्लॉक के बाहर घोषित किया जाता है और जिसे फंक्शन के अंदर एक्सेस किया जा सकता है, ग्लोबल वेरिएबल्स कहलाता है।A variable that is declared outside of a function block and can be accessed inside the function is called global variables.
Bग्लोबल वेरिएबल को परिभाषित करने के बाद, सिस्टम या कंपाइलर इसके लिए कोई मान प्रारंभ नहीं करेगा। आपको इसे खुद से इनिशियलाइज़ करना होगा।After defining a global variable, the system or the compiler won't be initialize any value to it. You have to initialize it by yourself.
Cये चर कार्यक्रम के अंत तक अपने मूल्यों को बनाए रखते हैं और आपके कार्यक्रम में परिभाषित किसी भी फ़ंक्शन के भीतर पहुंच योग्य होते हैं।These variables hold their values all through the end of the program and are accessible within any of the functions defined in your program.
Dकोई भी फ़ंक्शन वैश्विक दायरे में परिभाषित वेरिएबल्स तक पहुंच सकता है, यानी, इसकी उपलब्धता घोषित होने के बाद पूरे कार्यक्रम के लिए बनी रहती है।Any function can access variables defined within the global scope, i.e., its availability stays for the entire program after being declared.
Aकिसी फ़ंक्शन के भीतर घोषित वेरिएबल किसी फ़ंक्शन के बाहर घोषित चर से भिन्न होता है।Variable declared within a function is different from a variable declared outside of a function.
Bएक वेरिएबल जिसे फंक्शन ब्लॉक के भीतर घोषित किया जाता है और केवल फंक्शन के भीतर ही इस्तेमाल किया जा सकता है, लोकल वेरिएबल्स कहलाता है।A variable that are declared within the function block and can be used only within the function is called local variables.
Cये सभी स्थानीय रूप से स्कोप किए गए कथन {} कर्ली ब्रेसिज़ के बजाय () कोष्ठक में लिखे और संलग्न हैं।All these locally scoped statements are written and enclosed within () parenthesis instead of {} curly braces.
Dएक ब्लॉक के भीतर घोषित किए गए वेरिएबल को उस विशिष्ट ब्लॉक और उस ब्लॉक के अन्य सभी आंतरिक ब्लॉकों के भीतर एक्सेस किया जा सकता है, लेकिन उन वेरिएबल को ब्लॉक के बाहर एक्सेस नहीं किया जा सकता है।Variable(s) that are declared within a block can be accessed within that specific block and all other inner blocks of that block, but those variables cannot be accessed outside the block.
Aघोषणा करते समय एक चर के लिए मेमोरी स्पेस आवंटित नहीं किया जाता है। यह केवल परिवर्तनीय परिभाषा या असाइनमेंट पर होता है।Memory space is not allocated for a variable while declaration. It happens only on the variable definition or assignment.
Bवेरिएबल इनिशियलाइज़ेशन का अर्थ है वेरिएबल को एक मान निर्दिष्ट करना।Variable initialization means assigning a value to the variable.
Cसमान चर नाम का उपयोग समान दायरे में किया जा सकता है।Same variable name can be used in same scope.
Dवेरिएबल्स का दायरा प्रोग्राम के उस क्षेत्र को संदर्भित करता है जहां वेरिएबल्स को इसकी घोषणा के बाद एक्सेस किया जा सकता है।The scope of variables refers to the area of the program where the variables can be accessed after its declaration.
Aप्रोग्रामिंग में, एक चर डेटा रखने के लिए एक कंटेनर (भंडारण क्षेत्र) है।In programming, a variable is a container (storage area) to hold data.
Bउपयोग करने से पहले C प्रोग्राम में वेरिएबल्स को घोषित नहीं किया जाना चाहिए।Variables should not be declared in the C program before to use.
Cभंडारण क्षेत्र को इंगित करने के लिए, प्रत्येक चर को एक अद्वितीय नाम (चर) दिया जाता है।To indicate the storage area, each variable is given a unique name (variable).
Dवेरिएबल के नाम मेमोरी स्थान का केवल प्रतीकात्मक रूप हैं।Variable names are just the symbolic representation of a memory location.