पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
नीचे दिए गए प्रोग्राम का आउटपुट बताइए।
#include <stdio.h>
int main()
{
int i;
if (printf("0"))
i = 3;
else
i = 5;
printf("%d", i);
return 0;
}
Predict the output of the program given below.
#include <stdio.h>
int main()
{
int i;
if (printf("0"))
i = 3;
else
i = 5;
printf("%d", i);
return 0;
}
A3
B5
C03
D05
सही उत्तर / Answer: (C)
हल / Solution
printf पहले अपना छापने का काम करता है और फिर छपे अक्षरों की गिनती लौटाता है। यहाँ वह एक अक्षर शून्य छापता है और 1 लौटाता है, इसलिए पर्दे पर पहला अक्षर शून्य आ जाता है। लौटा हुआ 1 शून्य नहीं है, सो शर्त सत्य है और i को 3 मिलता है। अंत में दूसरा printf वही 3 छापता है। दोनों हिस्से मिलकर आउटपुट 03 बनाते हैं; 5 तभी आता जब printf शून्य लौटाता।
printf does its printing first and then returns the count of characters written. Here it prints the single character zero and returns 1, so a zero already appears on the screen. The returned 1 is non zero, so the condition is true and i receives 3. At the end the second printf prints that 3. The two parts together give the output 03.
प्रश्न 2उत्तर + हल
निम्नलिखित C प्रोग्राम का आउटपुट क्या होगा?
#include <stdio.h>
int main(){
int a=5, b=7;
if(5<a){
printf("Delhi");
}
printf("Gurugram");
if(3<b)
printf("Banglore");
else
printf("Chennai");
else
printf("Jaipur");
}
What will be the output of the following C program?
#include <stdio.h>
int main(){
int a=5, b=7;
if(5<a){
printf("Delhi");
}
printf("Gurugram");
if(3<b)
printf("Banglore");
else
printf("Chennai");
else
printf("Jaipur");
}
ADelhiGurugramBanglore
BDelhiGurugram
CJaipur
DCompile Time Error
सही उत्तर / Answer: (D)
हल / Solution
तीसरी शर्त के साथ एक else पहले से जुड़ चुका है, जो Chennai छापता। उसके बाद एक और else लिखा गया है, पर उसके लिए कोई बिना-else वाला if बचा ही नहीं — ऊपर का पहला if अपने कोष्ठक के साथ कभी पहले ही पूरा हो गया था। बिना if वाला else संकलक (compiler) की ग़लती है, सो संकलन वहीं रुक जाता है। चूँकि प्रोग्राम बनता ही नहीं, Delhi या Gurugram छपने का सवाल नहीं उठता।
The third condition already has one else attached to it, the one that would print Chennai. After that a second else is written, but no if without an else is left for it, because the first if above was completed long before with its own closing brace. An else with no matching if is a compile error, so compilation stops at that point. Since no program is built, neither Delhi nor Gurugram can be printed at all.
प्रश्न 3उत्तर + हल
निम्नलिखित C प्रोग्राम का आउटपुट क्या होगा?
#include <stdio.h>
int main(){
int a=5, b=7;
if(a<b)
if(0)
printf("FliQi");
else
printf("Mera BHARAT");
else
printf("Mera TIRANGA, Meri SHAAN");
}
What will be the output of the following C program?
#include <stdio.h>
int main(){
int a=5, b=7;
if(a<b)
if(0)
printf("FliQi");
else
printf("Mera BHARAT");
else
printf("Mera TIRANGA, Meri SHAAN");
}
AFliQi
BMera BHARAT
CMera TIRANGA, Meri SHAAN
DMera BharatMera TIRANGA, Meri SHAAN
सही उत्तर / Answer: (B)
हल / Solution
कोष्ठक न होने पर else सबसे पास वाले, बिना else वाले if से जुड़ता है। इसलिए पहला else भीतरी शर्त का है और दूसरा else बाहरी शर्त का। a का b से छोटा होना सत्य है, सो नियंत्रण भीतर जाता है; वहाँ शर्त शून्य यानी असत्य है, इसलिए उसी का else चलकर Mera BHARAT छापता है। बाहरी शर्त सत्य थी, सो उसका else छूट जाता है और तिरंगे वाला संदेश नहीं छपता। दोनों एक साथ कभी नहीं आ सकते।
Without braces an else joins the nearest if that does not have one yet. So the first else belongs to the inner condition and the second else to the outer one. Since a is smaller than b, control enters the inner if, whose condition is zero and therefore false, so its else runs and prints Mera BHARAT. The outer condition was true, so its own else is skipped and the tiranga message is not printed. Both can never appear together.
प्रश्न 4उत्तर + हल
निम्नलिखित C प्रोग्राम का आउटपुट क्या होगा?
#include <stdio.h>
int main(){
int a=5, b=7;
if(a>b){
if(1){
printf("FliQi");
}
}
else{
printf("My FliQi");
}
}
What will be the output of the following C program?
#include <stdio.h>
int main(){
int a=5, b=7;
if(a>b){
if(1){
printf("FliQi");
}
}
else{
printf("My FliQi");
}
}
AFliQi
BMy FliQi
CPrint Nothing
DCompile Time Error
सही उत्तर / Answer: (B)
हल / Solution
यहाँ कोष्ठक साफ़-साफ़ लगे हैं, इसलिए else बाहरी if का ही है, भीतरी if का नहीं। a 5 और b 7 है, सो बाहरी शर्त असत्य निकलती है और भीतर का वह भाग, जिसमें FliQi छपता, चलता ही नहीं। नियंत्रण सीधे else वाले ब्लॉक में जाता है और My FliQi छपता है। कुछ न छपना तब होता जब else ही न होता, और कोड पूरी तरह वैध है, इसलिए कम्पाइल टाइम एरर भी नहीं आता।
The braces here are explicit, so the else belongs to the outer if and not to the inner one. With a as 5 and b as 7 the outer test is false, so the inner block that would print FliQi never runs. Control moves straight into the else block and My FliQi is printed. The code is entirely valid, so no compile time error arises.
प्रश्न 5उत्तर + हल
निम्नलिखित C प्रोग्राम का आउटपुट क्या होगा?
#include <stdio.h>
int main(){
int a=5, b=7;
if(a>b)
if(1)
printf("FliQi");
else
printf("FliQi Education");
}
What will be the output of the following C program?
#include <stdio.h>
int main(){
int a=5, b=7;
if(a>b)
if(1)
printf("FliQi");
else
printf("FliQi Education");
}
AFliQi
BFliQi Education
CPrint Nothing
DCompile Time Error
सही उत्तर / Answer: (C)
हल / Solution
यहाँ कोष्ठक नहीं हैं, इसलिए लटकते else (dangling else) के नियम से else भीतरी if के साथ जुड़ता है, बाहरी if के साथ नहीं। a 5 और b 7 है, सो बाहरी शर्त असत्य है और उसके अधीन पड़ा पूरा भीतरी if-else ढाँचा एक ही कथन की तरह छूट जाता है। नतीजा यह कि कुछ भी नहीं छपता। FliQi Education पाने के लिए बाहरी if को { } में बाँधना पड़ता, तभी else उसका होता और असत्य शर्त पर चलता।
There are no braces here, so by the dangling else rule the else attaches to the inner if and not to the outer one. With a as 5 and b as 7 the outer test is false, and the whole inner if-else structure, a single statement under it, is skipped together. Nothing is printed at all. To get FliQi Education the outer if would need braces.
प्रश्न 6उत्तर + हल
निम्नलिखित C प्रोग्राम का आउटपुट क्या होगा?
#include <stdio.h>
int main(){
int a=5, b=7;
if(a<b){
printf("Jaipur");
if(!3){
printf("Delhi");
}
if(!17<10){
printf("Mumbai");
}
}
printf("Vandey Matram");
}
What will be the output of the following C program?
#include <stdio.h>
int main(){
int a=5, b=7;
if(a<b){
printf("Jaipur");
if(!3){
printf("Delhi");
}
if(!17<10){
printf("Mumbai");
}
}
printf("Vandey Matram");
}
AVandey Matram
BJaipurDelhiVandey Matram
CJaipurMumbaiVandey Matram
DDelhiMumbaiVandey Matram
सही उत्तर / Answer: (C)
हल / Solution
a का b से छोटा होना सत्य है, सो Jaipur छपता है। इसके बाद 3 सत्य है, इसलिए उसका उलटा शून्य हुआ और Delhi छूट गया। अब तीसरी शर्त ध्यान से देखिए — ! की प्राथमिकता (precedence) < से ऊँची है, इसलिए पहले 17 का उलटा शून्य बनता है और फिर शून्य का 10 से छोटा होना जाँचा जाता है, जो सत्य है; इसी से Mumbai छपता है। अंत में ब्लॉक के बाहर वाला printf हर हाल में चलता है।
The test that a is smaller than b is true, so Jaipur is printed. Next, 3 is true, so its negation is zero and Delhi is skipped. Now look carefully at the third condition: the ! operator has higher precedence than <, so 17 is negated to zero first and then zero is compared with 10, which is true, and Mumbai is printed. Finally the printf outside the block always runs, giving JaipurMumbaiVandey Matram as the whole output.
प्रश्न 7उत्तर + हल
निम्नलिखित C प्रोग्राम का आउटपुट क्या होगा?
#include <stdio.h>
int main(){
int a=5, b=7;
if(a>b);
printf("FliQi");
if(10)
printf("Jai Hind");
else
printf("FliQi Education");
}
What will be the output of the following C program?
#include <stdio.h>
int main(){
int a=5, b=7;
if(a>b);
printf("FliQi");
if(10)
printf("Jai Hind");
else
printf("FliQi Education");
}
AJai Hind
BFliQi
CFliQi Jai Hind
DFliQi FliQi Education
सही उत्तर / Answer: (C)
हल / Solution
if(a>b); में अर्धविराम (semicolon) ही उसका खाली कथन (empty statement) बन जाता है, इसलिए शर्त असत्य होने पर भी आगे वाला printf उसके अधीन नहीं रहता और FliQi हर हाल में छपता है। इसके बाद if(10) में 10 शून्य नहीं है, सो शर्त सत्य है और Jai Hind छपता है, else छूट जाता है। दोनों मिलकर पूरा आउटपुट बनता है। असली सबक़ यह है कि if के आगे रखा अर्धविराम बड़ी और चुपचाप बैठी चूक है।
In if(a>b); the semicolon itself becomes the empty statement controlled by the if, so the printf that follows is no longer under that condition and FliQi is printed whatever the values are. Next, in if(10) the value 10 is non zero, so the condition is true, Jai Hind is printed and the else is skipped. The two together make the full output. The real lesson is that a stray semicolon after if is a serious and silent mistake.
प्रश्न 8उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
int a=10;
if(10L == a)
printf("10L");
else if(10==a)
printf("10");
else
printf("0");
return 0;
}
What will be the output of the following program?
#include <stdio.h>
int main()
{
int a=10;
if(10L == a)
printf("10L");
else if(10==a)
printf("10");
else
printf("0");
return 0;
}
A10
B10L
C10L10
DERROR
सही उत्तर / Answer: (B)
हल / Solution
10L एक long स्थिरांक (constant) है, पर तुलना से पहले C दोनों पक्षों को एक ही टाइप में ले आता है — इसे सामान्य अंकगणितीय रूपांतरण (usual arithmetic conversion) कहते हैं। a का मान 10 long बनकर 10L के बराबर निकलता है, सो पहली शर्त ही सत्य है और उसी का printf चलता है। if-else की शृंखला में पहली सत्य शर्त के बाद बाक़ी जाँचें छूट जाती हैं।
10L is a long constant, but before comparing, C brings both sides to one common type through the usual arithmetic conversions. The value 10 held in a becomes a long and matches 10L, so the very first condition is true and its printf runs. In an if-else chain the remaining tests are skipped once a condition succeeds, so 10 is never printed and the two outputs can never appear together. The code is valid, so there is no error.
प्रश्न 9उत्तर + हल
निम्नलिखित में से कौन-से कथन ग़लत हैं? यदि int a=10 हो:
1) if( a==10 ) printf("IncludeHelp");
2) if( 10==a ) printf("IncludeHelp");
3) if( a=10 ) printf("IncludeHelp");
4) if( 10=a ) printf("IncludeHelp");
Which of the following are incorrect statements, if int a=10?
1) if( a==10 ) printf("IncludeHelp");
2) if( 10==a ) printf("IncludeHelp");
3) if( a=10 ) printf("IncludeHelp");
4) if( 10=a ) printf("IncludeHelp");
A3 and 4
B3 only
C4 only
D2,3 and 4
सही उत्तर / Answer: (C)
हल / Solution
कथन 1 और 2 दोनों ठीक हैं; a==10 और 10==a एक ही तुलना हैं, और दूसरा रूप तो भूल से एक बराबर लिखने से बचा लेता है। कथन 3 भी वैध C है — वहाँ a को 10 दिया जाता है और वही मान शर्त बन जाता है; संकलक चेतावनी दे सकता है, पर यह ग़लती नहीं। कथन 4 में बाईं ओर स्थिरांक 10 है, जबकि वहाँ बदला जा सकने वाला चर (lvalue) चाहिए। इसलिए केवल कथन 4 ग़लत है।
Statements 1 and 2 are both fine, because a==10 and 10==a are the same comparison, and the second form even guards against typing a single equals sign by mistake. Statement 3 is valid C too: it assigns 10 to a and uses that value as the condition, and a compiler may warn but this is not an error. Statement 4 puts the constant 10 on the left, where a modifiable variable is needed. So only statement 4 is incorrect.
प्रश्न 10उत्तर + हल
निम्नलिखित प्रोग्राम का आउटपुट क्या होगा?
#include <stdio.h>
int main()
{
int pn=100;
if(pn>20)
if(pn<20)
printf("Heyyyyy");
else
printf("Hiiiii");
return 0;
}
What will be the output of the following program?
#include <stdio.h>
int main()
{
int pn=100;
if(pn>20)
if(pn<20)
printf("Heyyyyy");
else
printf("Hiiiii");
return 0;
}
ANo output
BHiiiii
CHeyyyyy
DHeyyyyyHiiiii
सही उत्तर / Answer: (B)
हल / Solution
यह लटकते else (dangling else) का प्रश्न है। C का नियम है कि else सबसे पास वाले, बिना else वाले if से जुड़ता है — इंडेंट (indent) से कुछ तय नहीं होता। इसलिए यहाँ else भीतरी if का है, बाहरी का नहीं। pn 100 है, सो बाहरी शर्त सत्य है और नियंत्रण भीतर पहुँचता है; वहाँ pn का 20 से छोटा होना असत्य है, इसलिए उसी का else चलकर Hiiiii छापता है।
This is the dangling else problem. The rule in C is that an else joins the nearest preceding if that does not already have one, and indentation decides nothing. So the else here belongs to the inner if and not to the outer one. Since pn is 100 the outer test is true and control enters the inner if, where the inner test is false, so its else prints Hiiiii.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति