पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
निम्न प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
int main()
{
int i = 4;
do{
printf("FliQi ");
}while(i==4);
return 0;
}
Find the output of the following program.
#include<stdio.h>
int main()
{
int i = 4;
do{
printf("FliQi ");
}while(i==4);
return 0;
}
AFliQi FliQi FliQi FliQi
BFliQi
CInfinite Loop
DPrint Nothing
सही उत्तर / Answer: (C)
हल / Solution
do-while का शरीर एक बार चलकर FliQi छापता है, फिर शर्त जाँची जाती है। i को 4 दिया गया था और लूप के भीतर उसे बदलने वाला कोई कथन नहीं है — न बढ़ोतरी है और न कोई नया मान। इसलिए शर्त हमेशा सत्य रहती है और लूप कभी नहीं रुकता, यानी यह अनंत लूप (infinite loop) है। बाहर निकलने के लिए भीतर i का मान बदलना पड़ता या break लगाना पड़ता। एक ही बार छपकर रुकना यहाँ असंभव है।
The body of the do-while runs once and prints FliQi, and then the condition is tested. The value 4 was given to i, and nothing inside the loop ever changes it; there is no increment and no fresh assignment. The condition therefore stays true for ever and the loop never stops, which makes it an infinite loop. A break would be needed to leave it.
प्रश्न 2उत्तर + हल
निम्न प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
int main()
{
int i = 4, j = 7;
do{
printf("India");
}while(++i < --j);
return 0;
}
Find the output of the following program.
#include<stdio.h>
int main()
{
int i = 4, j = 7;
do{
printf("India");
}while(++i < --j);
return 0;
}
AIndia India India
BIndia India
CIndia India India India
DInfinite Loop
सही उत्तर / Answer: (B)
हल / Solution
do-while पहले शरीर चलाता है और शर्त बाद में जाँचता है। पहला चक्कर — India छपा, फिर i 5 और j 6 हो गए; 5 का 6 से छोटा होना सत्य है, सो लूप दोबारा चलेगा। दूसरा चक्कर — India छपा, अब i 6 और j 5 हुए; 6 का 5 से छोटा होना असत्य है, इसलिए लूप रुक जाता है। कुल दो बार India छपता है।
A do-while runs its body first and checks the condition afterwards. First round: India is printed, then i becomes 5 and j becomes 6, and since 5 is smaller than 6 the loop repeats. Second round: India is printed, now i is 6 and j is 5, and 6 is not smaller than 5, so the loop ends. India is therefore printed exactly twice. Note that both are pre operators, so the updated values are the ones being compared.
प्रश्न 3उत्तर + हल
निम्न प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
int main()
{
int i = 1;
while(i){
printf("India ");
i++;
if(i == 5)
printf("Bye Bye ");
}
return 0;
}
Find the output of the following program.
#include<stdio.h>
int main()
{
int i = 1;
while(i){
printf("India ");
i++;
if(i == 5)
printf("Bye Bye ");
}
return 0;
}
AIndia India India India India Bye Bye
BIndia will be printed 5 Times
CInfinite Loop
DBye Bye
सही उत्तर / Answer: (C)
हल / Solution
शर्त में सिर्फ़ i लिखा है, यानी लूप तब तक चलेगा जब तक i शून्य न हो जाए। भीतर i केवल बढ़ता है, इसलिए वह कभी शून्य पर नहीं लौटता और लूप के ख़त्म होने का कोई रास्ता नहीं बचता। i के 5 होने पर Bye Bye एक बार छपता है, पर वह लूप रोकता नहीं, क्योंकि वहाँ न break है और न शर्त बदलती है। इसलिए यह अनंत लूप (infinite loop) है; India पाँच बार छपकर रुकने वाला नहीं।
The condition is just i, so the loop keeps running as long as i is not zero. Inside the body i only grows, so it never comes back to zero and the loop has no way of ending. When i becomes 5 the message Bye Bye is printed once, but that stops nothing, because there is no break there and the condition is never changed. So this is an infinite loop, and India is certainly not printed just five times.
प्रश्न 4उत्तर + हल
निम्न प्रोग्राम का आउटपुट क्या होगा?
#include<stdio.h>
int main()
{
int a = 3, b = 7;
while(a<=5, b<=15){
printf("FliQi ");
a++;
b++;
}
return 0;
}
Find the output of the following program.
#include<stdio.h>
int main()
{
int a = 3, b = 7;
while(a<=5, b<=15){
printf("FliQi ");
a++;
b++;
}
return 0;
}
AFliQi will be printed 2 times
BFliQi will be printed 3 times
CFliQi will be printed 8 times
DFliQi will be printed 9 times
सही उत्तर / Answer: (D)
हल / Solution
शर्त में अल्पविराम संचालक (comma operator) लगा है। वह बाएँ भाग को जाँचकर उसका नतीजा फेंक देता है और पूरी अभिव्यक्ति का मान दाएँ भाग से लेता है, इसलिए असली शर्त सिर्फ़ b का 15 तक होना है; a वाली शर्त का कोई असर नहीं। b 7 से शुरू होकर हर चक्कर में एक बढ़ता है, सो नौ बार शर्त सत्य रहती है और FliQi नौ बार छपता है।
The condition uses the comma operator. It evaluates the left part, throws that result away, and takes the value of the whole expression from the right part, so the real test is only on b and the test on a has no effect. Starting at 7, b rises by one each round, so the test stays true nine times and FliQi is printed nine times.
प्रश्न 5उत्तर + हल
आउटपुट का पता लगाएं #include<stdio.h>
int main()
{
int i = 5;
while(i){
printf("FliQi ");
i--;
}
return 0;
}
Find Output #include<stdio.h>
int main()
{
int i = 5;
while(i){
printf("FliQi ");
i--;
}
return 0;
}
AFliQi
BFliQi FliQi FliQi FliQi FliQi
CFliQi FliQi FliQi FliQi
Dअनंत लूपInfinite Loop
सही उत्तर / Answer: (B)
हल / Solution
while(i) तब तक सही है जब तक i शून्य न हो। i की शुरुआत 5 से होती है। हर चक्र में FliQi छपता है और i-- से i एक घटता है। i = 5, 4, 3, 2, 1 पर शर्त सही है, इसलिए FliQi पाँच बार छपता है। i = 0 होते ही लूप रुकता है। चार बार गिनने में i = 1 वाला चक्र छूटता है। i घटता है, इसलिए लूप अनंत नहीं है।
while(i) is true as long as i is not zero. i starts at 5. In each pass FliQi is printed and i-- reduces i by one. The condition is true for i = 5, 4, 3, 2 and 1, so FliQi is printed five times. When i becomes 0 the condition fails and the loop stops. Counting four times misses the pass with i = 1. Since i keeps falling, the loop is not infinite.
प्रश्न 6उत्तर + हल
आउटपुट का पता लगाएं #include<stdio.h>
int main()
{
int a = 5;
while(a<=9){
printf("%d",a);
}
return 0;
}
Find Output #include<stdio.h>
int main()
{
int a = 5;
while(a<=9){
printf("%d",a);
}
return 0;
}
A5 4 3 2 1
B9 8 7 6 5 4 3 2 1
C9 8 7 6 5
Dअनंत लूपInfinite Loop
सही उत्तर / Answer: (D)
हल / Solution
a की शुरुआत 5 से होती है और शर्त है कि a नौ या उससे छोटा हो। 5 के लिए यह सही है, इसलिए 5 छपता है। पर body में a को बदलने वाला कोई स्टेटमेंट नहीं — न a++, न a--। इसलिए a हमेशा 5 रहता है और 5 बिना रुके छपता है। यह अनंत लूप है। बाक़ी तीनों विकल्प घटती गिनती दिखाते हैं, जो a-- के बिना हो ही नहीं सकती।
a starts at 5, and the condition asks a to be 9 or less. That is true for 5, so the body runs and prints 5. But nothing in the body changes a: there is no a++ and no a--. So a stays 5, the condition stays true, and 5 is printed again and again. This is an infinite loop. The other three options show a falling count, which is impossible without something like a--.
प्रश्न 7उत्तर + हल
आउटपुट का पता लगाएं #include<stdio.h>
int main()
{
int i = 5;
while(i=8){
printf("%d ",i);
i--;
}
return 0;
}
Find Output #include<stdio.h>
int main()
{
int i = 5;
while(i=8){
printf("%d ",i);
i--;
}
return 0;
}
A5 4 3 2 1
B8 7 6 5 4 3 2 1
C8 7 6 5
Dअनंत लूपInfinite Loop
सही उत्तर / Answer: (D)
हल / Solution
while(i=8) में == नहीं, = है, यानी यह assignment है। हर जाँच पर i में 8 रखा जाता है और व्यंजक का मान 8 होता है, जो सही (true) है। body में 8 छपता है और i-- से i 7 होता है, पर अगली जाँच उसे फिर 8 बना देती है। इसलिए 8 बिना रुके छपता है और लूप अनंत है। 8 से 1 तक की गिनती के लिए शर्त सिर्फ़ i होनी चाहिए थी।
while(i=8) uses =, not ==, so it is an assignment. Each check sets i to 8, and the expression has the value 8, which is true. The body prints 8 and i-- makes i 7, but the next check sets it back to 8. So 8 is printed without end and the loop is infinite. A countdown from 8 to 1 would need the condition to be just i.
प्रश्न 8उत्तर + हल
आउटपुट का पता लगाएं #include<stdio.h>
int main()
{
int i = 0;
do{
printf("FliQi India");
}while(i!=0);
return 0;
}
Find Output #include<stdio.h>
int main()
{
int i = 0;
do{
printf("FliQi India");
}while(i!=0);
return 0;
}
Aकुछ भी प्रिंट नहीं होगाPrint Nothing
BFliQi India
CFliQi India अनंत बार प्रिंट होगाFliQi India will be printed Infinite times
DCompile Time Error
सही उत्तर / Answer: (B)
हल / Solution
do-while में body पहले चलती है और शर्त बाद में जाँची जाती है। इसलिए पहले FliQi India एक बार छपता है। फिर शर्त i != 0 जाँची जाती है। i का मान 0 है, इसलिए यह शर्त झूठी है और लूप रुक जाता है। आउटपुट एक बार FliQi India है। do-while कम से कम एक बार चलता है, इसलिए कुछ न छपना ग़लत है। i कभी नहीं बदलता, तो अनंत छपाई भी नहीं होती।
In a do-while the body runs first and the condition is checked afterwards. So FliQi India is printed once. Then the condition i != 0 is checked. i is 0, so the condition is false and the loop stops. The output is FliQi India just once. A do-while body always runs at least once, so Print Nothing is wrong. i never changes, so there is no endless printing either, and the code compiles fine.
प्रश्न 9उत्तर + हल
आउटपुट का पता लगाएं #include<stdio.h>
int main()
{
int i = 0;
while(++i)
printf("FliQi");
return 0;
}
Find Output #include<stdio.h>
int main()
{
int i = 0;
while(++i)
printf("FliQi");
return 0;
}
Aकुछ भी प्रिंट नहीं होगाPrint Nothing
BFliQi
CFliQi अनंत बार प्रिंट होगाFliQi will be printed Infinite times
DCompile Time Error
सही उत्तर / Answer: (C)
हल / Solution
i की शुरुआत 0 से होती है। while(++i) में pre-increment है, यानी पहले i बढ़ता है, फिर जाँच होती है। i क्रम से 1, 2, 3 … बनता है, सब शून्य से अलग, इसलिए शर्त हमेशा सही रहती है और FliQi अनंत बार छपता है। int की सीमा पार होना undefined behaviour है, उसके भरोसे लूप नहीं रुकता। i++ होता तो शुरू का 0 जाँचा जाता और कुछ न छपता। syntax सही है, इसलिए compile error नहीं।
i starts at 0. The condition while(++i) uses pre-increment, so i is increased first and the new value is tested. On the first check i is 1, which is true, and FliQi is printed. Then i becomes 2, 3, 4 and so on, all non-zero, so the condition is always true and FliQi is printed infinitely. Going past the int limit is undefined behaviour. With i++ the old value 0 would be tested and nothing would print.
प्रश्न 10उत्तर + हल
निम्नलिखित C कोड का आउटपुट क्या होगा? #include <stdio.h>
int main()
{
while()
printf("In loop ");
printf("After loop");
}
What will be the output of the following C code? #include <stdio.h>
int main()
{
while()
printf("In loop ");
printf("After loop");
}
AIn loop after loop
BAfter loop
CCompile time error
Dअनंत लूपInfinite loop
सही उत्तर / Answer: (C)
हल / Solution
while() के कोष्ठक ख़ाली हैं। for लूप में शर्त छोड़ी जा सकती है, पर while लूप में शर्त लिखना ज़रूरी है। ख़ाली शर्त देखकर compiler expected expression जैसी error देता है और प्रोग्राम बनता ही नहीं। इसलिए न In loop छपता है, न After loop। अनंत लूप भी तभी बनता जब while(1) लिखा होता। यहाँ प्रोग्राम compile ही नहीं होता, इसलिए सही उत्तर compile time error है।
The brackets of while() are empty. A for loop may leave out its condition, but a while loop must have one. Seeing an empty condition, the compiler reports an error such as expected expression, and no program is built. So neither In loop nor After loop is printed. An infinite loop would need something like while(1). Here the program does not even compile, so the answer is a compile time error.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति