पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
आउटपुट ज्ञात कीजिए
#include <stdio.h>
int main() {
int i;
for(printf(" MyFliQi ");printf(" India ");printf(" i++ ")){
printf(" FliQi ");
}
return 0;
}
Find the Output
#include <stdio.h>
int main() {
int i;
for(printf(" MyFliQi ");printf(" India ");printf(" i++ ")){
printf(" FliQi ");
}
return 0;
}
Aकंपाइल टाइम एररCompile Time Error
Bपहले MyFliQi, फिर India FliQi i++ 5 बारMyFliQi then India FliQi i++ 5 times
Cपहले MyFliQi, फिर India FliQi i++ अनंत बारMyFliQi then India FliQi i++ Infinite times
DMyFliQi FliQI India i++
सही उत्तर / Answer: (C)
हल / Solution
for के शीर्ष के किसी भी भाग में function call हो सकता है। पहला printf एक बार MyFliQi छापता है। शर्त India वाला printf है, और printf छपे हुए अक्षरों की संख्या लौटाता है, यहाँ 7। 7 शून्य नहीं है, इसलिए शर्त हमेशा सत्य है। इसलिए MyFliQi के बाद India, FliQi, i++ का क्रम लगातार दोहराता है। i++ बस उद्धरण में लिखा पाठ है, वह कुछ नहीं बदलता।
Any function call can be a part of a for header. The init printf prints MyFliQi once. The condition is the printf of India, and printf returns the number of characters it printed, here 7. Since 7 is non-zero, the test is always true. So after MyFliQi, the pattern India, FliQi, i++ repeats forever. The i++ is only text inside quotes and changes nothing. The code compiles fine.
प्रश्न 2उत्तर + हल
आउटपुट ज्ञात कीजिए
#include <stdio.h>
int main() {
int i = 400;
for(; i ; i>>=2){
printf("FliQi");
}
return 0;
}
Find the Output
#include <stdio.h>
int main() {
int i = 400;
for(; i ; i>>=2){
printf("FliQi");
}
return 0;
}
AFliQi 400 बार छपेगाFliQi Will be printed 400 times
BFliQi 100 बार छपेगाFliQi Will be printed 100 times
CFliQi 10 बार छपेगाFliQi Will be printed 10 times
DFliQi 5 बार छपेगाFliQi Will be printed 5 times
सही उत्तर / Answer: (D)
हल / Solution
i >>= 2 से i दो bit दाईं ओर खिसकता है, यानी 4 से भाग होता है और शेष छूट जाता है। मान होंगे 400, 100, 25, 6 और 1। ये सब शून्य नहीं हैं, इसलिए हर एक पर FliQi छपता है, यानी 5 बार। फिर 1 >> 2 से 0 बनता है, शर्त i असत्य हो जाती है और लूप रुकता है। विकल्प 1, 2 और 3 मान लेते हैं कि लूप 400, 100 या 10 बार चलेगा।
i >>= 2 shifts i right by two bits, which is the same as dividing by 4 and dropping the remainder. The values are 400, 100, 25, 6 and 1. Each of them is non-zero, so FliQi is printed for each: 5 times. Next, 1 >> 2 gives 0, the test i becomes false and the loop stops. Options 1, 2 and 3 assume the loop runs 400, 100 or 10 times.
प्रश्न 3उत्तर + हल
आउटपुट ज्ञात कीजिए
#include <stdio.h>
int main() {
int i = 1;
for(i = 10;i>=20;i++){
printf(" FliQi ");
}
return 0;
}
Find the Output
#include <stdio.h>
int main() {
int i = 1;
for(i = 10;i>=20;i++){
printf(" FliQi ");
}
return 0;
}
AFliQI 10 बार छपेगाFliQI will be printed 10 Times
BFliQI 11 बार छपेगाFliQI will be printed 11 Times
CFliQI अनंत बार छपेगाFliQI will be printed Infinite Times
DFliQI 0 बार छपेगाFliQI will be printed 0 Times
सही उत्तर / Answer: (D)
हल / Solution
पहला भाग i = 10 करता है। फिर पहले चक्कर से पहले ही शर्त i >= 20 जाँची जाती है। 10 न 20 से बड़ा है, न बराबर, इसलिए शर्त शुरू में ही असत्य है। body एक बार भी नहीं चलती, इसलिए FliQi 0 बार छपता है। लूप अनंत नहीं हो सकता, क्योंकि वह शुरू ही नहीं होता। 10 या 11 बार छपने के लिए शुरुआत में शर्त सत्य होनी चाहिए।
The init part sets i = 10, and then the condition i >= 20 is checked before the first pass. 10 is not greater than or equal to 20, so the condition is false right away. The body never runs, so FliQi is printed 0 times. The loop cannot become infinite, because it never even starts. Counts like 10 or 11 would need the test to be true at the beginning.
प्रश्न 4उत्तर + हल
आउटपुट ज्ञात कीजिए
#include <stdio.h>
int main() {
int i, j, n = 50;
for(i = 0, j = 0; i<3, j<=n; j+=5){
printf("FliQi");
}
return 0;
}
Find the Output
#include <stdio.h>
int main() {
int i, j, n = 50;
for(i = 0, j = 0; i<3, j<=n; j+=5){
printf("FliQi");
}
return 0;
}
AFliQi 3 बार छपेगाFliQi will be printed 3 times
BFliQi 50 बार छपेगाFliQi will be printed 50 times
CFliQi 10 बार छपेगाFliQi will be printed 10 Times
DFliQI 11 बार छपेगाFliQI will be printed 11 Times
सही उत्तर / Answer: (D)
हल / Solution
शर्त i<3, j<=n में comma ऑपरेटर लगा है। यह दोनों भाग चलाता है, पर मान सिर्फ़ दाएँ भाग का रखता है। इसलिए लूप सिर्फ़ j <= n से तय होता है, i का कोई असर नहीं। j के मान 0, 5, 10, ... 50 होंगे, यानी 50/5 + 1 = 11 मान। j = 55 पर शर्त असत्य हो जाती है। इसलिए FliQi 11 बार छपता है, न 3, न 10, न 50 बार।
The condition i<3, j<=n uses the comma operator. It evaluates both parts but keeps only the value of the right one, so only j <= n decides the loop. i stays 0 and does not matter. j takes the values 0, 5, 10, ... 50, which is 11 values, since 50/5 + 1 = 11. At j = 55 the test fails. So FliQi is printed 11 times, not 3, 10 or 50 times.
प्रश्न 5उत्तर + हल
आउटपुट ज्ञात कीजिए
#include <stdio.h>
int main() {
int i = 1;
for(printf("MyFliQi ");i<=5;i++){
printf(" FliQi ");
}
return 0;
}
Find the Output
#include <stdio.h>
int main() {
int i = 1;
for(printf("MyFliQi ");i<=5;i++){
printf(" FliQi ");
}
return 0;
}
AMyFliQi
BMyFliQi FliQi
CFliQi 5 बारFliQi 5 Times
Dपहले MyFliQI, फिर FliQi 5 बारMyFliQI then FliQi 5 times
सही उत्तर / Answer: (D)
हल / Solution
for लूप का पहला भाग सिर्फ़ एक बार चलता है। यहाँ वह printf है, इसलिए शुरुआत में MyFliQi एक बार छपता है। फिर i, 1 से 5 तक चलता है और हर चक्कर में body FliQi छापती है। i = 6 होते ही शर्त i <= 5 असत्य होती है और लूप रुकता है। इसलिए आउटपुट: पहले MyFliQi एक बार, फिर FliQi पाँच बार। विकल्प 1, 2 और 3 में कुछ छपाई छूट जाती है।
The init part of a for loop runs only once. Here it is a printf, so MyFliQi is printed one time at the start. Then i goes from 1 to 5, and in each pass the body prints FliQi. When i becomes 6, the test i <= 5 fails and the loop ends. So the output is MyFliQi once, followed by FliQi five times. Options 1, 2 and 3 miss some of these prints.
प्रश्न 6उत्तर + हल
आउटपुट ज्ञात कीजिए
#include <stdio.h>
int main() {
int i = 1, n = 5;
for(i = 1;i<=5;i++){
printf("%d ",i*n);
}
return 0;
}
Find the Output
#include <stdio.h>
int main() {
int i = 1, n = 5;
for(i = 1;i<=5;i++){
printf("%d ",i*n);
}
return 0;
}
A5 10 15 20 25
B1 2 3 4 5
C1*5 2*5 3*5 4*5 5*5
Dइनमें से कोई नहींNone of the above
सही उत्तर / Answer: (A)
हल / Solution
लूप i = 1 से 5 तक चलता है और n = 5 है। printf, i*n का मान छापता है, उसका पाठ नहीं। इसलिए 1*5 = 5, 2*5 = 10, 3*5 = 15, 4*5 = 20 और 5*5 = 25 छपते हैं, हर एक के बाद एक space। आउटपुट 5 10 15 20 25 है। विकल्प 2 सिर्फ़ i छापता, और विकल्प 3 गुणा को पाठ की तरह दिखाता है, जो ग़लत है।
The loop runs for i = 1 to 5, and n is 5. printf prints the value of the expression i*n, not its text. So it prints 1*5 = 5, 2*5 = 10, 3*5 = 15, 4*5 = 20 and 5*5 = 25, each followed by a space. The output is 5 10 15 20 25. Option 2 would print only i, and option 3 wrongly shows the multiplication as text.
प्रश्न 7उत्तर + हल
आउटपुट ज्ञात कीजिए
#include <stdio.h>
int main() {
int i = 1;
for(i = 1;i<=10;i++){
if(i%2==0)
printf("%d ",i);
}
return 0;
}
Find the Output
#include <stdio.h>
int main() {
int i = 1;
for(i = 1;i<=10;i++){
if(i%2==0)
printf("%d ",i);
}
return 0;
}
A1 3 5 7 9
B2 4 6 8 10
Cअनंत लूपInfinite Loop
Dकुछ नहीं छपेगाPrint Nothing
सही उत्तर / Answer: (B)
हल / Solution
लूप i = 1 से 10 तक चलता है। अंदर i % 2 == 0 तभी सत्य है जब i, 2 से पूरा बँटे, यानी सम संख्या हो। इसलिए printf सिर्फ़ 2, 4, 6, 8 और 10 के लिए चलता है। विषम संख्याएँ 1, 3, 5, 7, 9 छोड़ दी जाती हैं। i = 10 के बाद i++ से 11 होता है और लूप रुक जाता है। इसलिए आउटपुट 2 4 6 8 10 है, न अनंत लूप, न ख़ाली।
The loop runs for i = 1 to 10. Inside, i % 2 == 0 is true only when i is divisible by 2, that is, for even numbers. So printf runs only for 2, 4, 6, 8 and 10, each followed by a space. The odd numbers 1, 3, 5, 7 and 9 are skipped. After i = 10, i++ makes it 11 and the loop ends. So the output is 2 4 6 8 10.
प्रश्न 8उत्तर + हल
आउटपुट ज्ञात कीजिए
#include <stdio.h>
int main() {
int i = 1;
for(i = 1;i<=10;i+2){
printf("FliQi ");
}
return 0;
}
Find the Output
#include <stdio.h>
int main() {
int i = 1;
for(i = 1;i<=10;i+2){
printf("FliQi ");
}
return 0;
}
AFliQi 10 बार छपेगाFliQi will be printed 10 times
BFliQi 5 बार छपेगाFliQi will be printed 5 times
CFliQi अनंत बार छपेगाFliQi will be printed Infinite times
Dकुछ नहीं छपेगाPrint Nothing
सही उत्तर / Answer: (C)
हल / Solution
update भाग i+2 है। यह बस एक मान निकालता है, पर उसे i में वापस नहीं रखता। इसलिए i हमेशा 1 ही रहता है। i में 2 जोड़ने के लिए i += 2 लिखना पड़ता। i नहीं बदलता, तो शर्त i <= 10 हमेशा सत्य रहती है और FliQi लगातार छपता है। i += 2 होता तो 5 बार छपता, विकल्प 2 यही जाल है। 10 बार या कुछ न छपना भी ग़लत है।
The update part is i+2. It calculates a value but does not store it back in i, so i stays 1. To add 2 to i we need i += 2 or i = i + 2. Since i never changes, the test i <= 10 is always true and FliQi is printed forever. With i += 2 it would print 5 times, which is the trap in option 2. It is not 10 times or zero times either.
प्रश्न 9उत्तर + हल
आउटपुट ज्ञात कीजिए
#include <stdio.h>
int main() {
int i = 1;
for(;5;){
printf("FliQi ");
}
return 0;
}
Find the Output
#include <stdio.h>
int main() {
int i = 1;
for(;5;){
printf("FliQi ");
}
return 0;
}
AFliQi 0 बार छपेगाFliQi will be printed 0 times
BFliQi 5 बार छपेगाFliQi will be printed 5 times
CFliQi अनंत बार छपेगाFliQi will be printed Infinite times
Dकंपाइल टाइम एररCompile Time Error
सही उत्तर / Answer: (C)
हल / Solution
C में शून्य के अलावा हर मान सत्य माना जाता है। यहाँ शर्त स्थिर मान 5 है, जो शून्य नहीं है, इसलिए हमेशा सत्य है। लूप में ऐसा कुछ नहीं जो इसे बदले, और break भी नहीं है। इसलिए FliQi बिना रुके छपता रहता है। यहाँ 5 का मतलब पाँच बार नहीं है, वह बस एक सत्य मान है। कोड सही है, इसलिए compile error नहीं।
In C, any non-zero value counts as true. The condition here is the constant 5, which is non-zero, so it is always true. Nothing in the loop can change a constant, and there is no break. So FliQi is printed again and again without end. The number 5 does not mean five times; it is only a true value. The code is valid, so there is no compile error.
प्रश्न 10उत्तर + हल
आउटपुट ज्ञात कीजिए
#include <stdio.h>
int main() {
int i = 1;
for(printf("MyFliQi ");i<=5;printf(" FliQi ")){
printf(" FliQi ");
}
return 0;
}
Find the Output
#include <stdio.h>
int main() {
int i = 1;
for(printf("MyFliQi ");i<=5;printf(" FliQi ")){
printf(" FliQi ");
}
return 0;
}
AMyFliQi FliQi FliQi
Bपहले MyFliQi, फिर FliQi अनंत बारMyFliQi then FliQi Infinite times
Cपहले MyFliQi, फिर FliQi 5 बारMyFliQi then FliQi will be printed 5 times
Dकंपाइल टाइम एररCompile Time Error
सही उत्तर / Answer: (B)
हल / Solution
पहला भाग, यानी MyFliQi वाला printf, सिर्फ़ एक बार शुरुआत में चलता है। फिर शर्त i <= 5 जाँची जाती है। i = 1 है और उसे कोई नहीं बदलता, क्योंकि body और update दोनों बस FliQi छापते हैं। इसलिए शर्त हमेशा सत्य है और FliQi बार-बार छपता है। आउटपुट: पहले MyFliQi एक बार, फिर FliQi अनंत बार। यह 5 बार पर नहीं रुकता और कोड ठीक से compile होता है।
The init part, the printf of MyFliQi, runs only once at the start. After that the test i <= 5 is checked. i is 1 and nothing changes it, because both the body and the update only print FliQi. So the test is always true and FliQi is printed again and again. The output is MyFliQi once, then FliQi forever. It does not stop after 5 times, and the code compiles fine.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति
Aनियंत्रण for लूप में जाएगा ही नहींThe control won't fall into the for loop
Bshort की signed सीमा तक संख्याएँ छपेंगी और फिर runtime error आएगाNumbers will be displayed until the signed limit of short and throw a runtime error
Cshort की signed सीमा तक संख्याएँ छपेंगी और प्रोग्राम ठीक से समाप्त हो जाएगाNumbers will be displayed until the signed limit of short and program will successfully terminate
Dप्रोग्राम infinite loop में फँसकर बिना error के संख्याएँ छापता रहेगाThis program will get into an infinite loop and keep printing numbers with no errors
for लूप के बारे में निम्नलिखित में से कौन-सी टिप्पणियाँ सही हैं?
Which of the following comments about the for loop are correct?
Abreak का उपयोग उस goto के बराबर है जो लूप के ठीक बाद वाले कथन पर कूदता हैUsing break is equivalent to using a goto that jumps to the statement immediately following the loop
Bcontinue का उपयोग लूप के मौजूदा चक्कर का बचा हिस्सा छोड़ने के लिए होता हैcontinue is used to bypass the remainder of the current pass of the loop
Ccomma ऑपरेटर लगाने पर लौटाया गया मान दाएँ operand का मान होता हैif comma operator is used, then the value returned is the value of the right operand