पहले 10 प्रश्नों के उत्तर और हल यहीं खुले हैं; बाक़ी 20 के उत्तर और हल FliQi Question Bank app में।
भाषा
प्रश्न 1उत्तर + हल
निम्नलिखित में से कौन सा C कथन वाक्य-रचना की दृष्टि से सही है?
Which of the following C statement is syntactically correct?
Afor (;;);
Bfor (;);
Cfor ();
Dfor (.);
सही उत्तर / Answer: (A)
हल / Solution
for की वाक्य-रचना में कोष्ठक के भीतर ठीक दो अर्ध-विराम चाहिए, क्योंकि वे तीन खानों को अलग करते हैं — शुरुआत, शर्त और वृद्धि। खाने ख़ाली छोड़े जा सकते हैं, पर अर्ध-विराम नहीं छोड़े जा सकते। इसी से पहला रूप पूरी तरह वैध है और वह अनंत लूप बनाता है। दूसरे में एक अर्ध-विराम कम है, तीसरे में एक भी नहीं, और चौथे में बिंदु का कोई अर्थ नहीं — तीनों पर कंपाइलर त्रुटि देता है।
The syntax of for needs exactly two semicolons inside the parentheses, because they separate the three slots: initialisation, condition and increment. The slots themselves may be left empty, but the semicolons may not be dropped. That is why the first form is perfectly legal and builds an endless loop. The second has one semicolon too few, the third has none, and a lone dot in the fourth means nothing, so all three fail to compile.
प्रश्न 2उत्तर + हल
स्विच (switch) कथन का उपयोग किया जाता है —
A switch statement is used to
Aस्विचिंग चर (switching variable) के उपयोग के लिएTo use switching variable
Bप्रोग्राम में एक फंक्शन से दूसरे फंक्शन पर स्विच करने के लिएSwitch between functions in a program
Cएक चर से दूसरे चर पर स्विच करने के लिएSwitch from one variable to another variable
Dकिसी एक चर के अलग-अलग मानों से बनने वाली कई संभावनाओं में से चुनने के लिएTo choose from multiple possibilities which may arise due to different values of a variable
सही उत्तर / Answer: (D)
हल / Solution
switch एक व्यंजक का मान लेकर उसे एक-एक case लेबल से मिलाता है और जहाँ मेल बैठे वहीं से चलना शुरू कर देता है। यानी इसका काम किसी एक चर के अलग-अलग मानों से बनी कई संभावनाओं में से एक चुनना है — इसे बहु-शाखा चुनाव (multi-way branching) कहते हैं। नाम में «स्विच» होने से यह चर बदलता नहीं, और फंक्शनों के बीच कूदना भी इसका काम नहीं। इसीलिए चौथा विकल्प सही है।
A switch takes the value of one expression, matches it against the case labels one by one and starts running from the label that matches. Its job is therefore to choose among the several possibilities created by the different values of a single variable, which is called multi-way branching. The word switch in its name does not mean it swaps variables, and jumping between functions is not its work either, so the fourth option is right.
प्रश्न 3उत्तर + हल
CONTINUE कथन का उपयोग किसके साथ नहीं किया जा सकता?
The CONTINUE statement cannot be used with
Afor
Bswitch
Cdo While
Dwhile
सही उत्तर / Answer: (B)
हल / Solution
continue का अर्थ है «लूप का बचा हिस्सा छोड़ो और अगला चक्कर शुरू करो», इसलिए वह सिर्फ़ for, while और do-while में अर्थ रखता है। switch में चक्कर जैसा कुछ होता ही नहीं, सो अकेले switch के शरीर में continue लिखने पर कंपाइलर त्रुटि देता है। हाँ, switch किसी लूप के भीतर पड़ा हो तो वहाँ लिखा continue भीतर के switch को छोड़कर उस लूप पर असर डालता है। switch से बाहर निकलने का कथन break है।
continue means skip the rest of the loop body and start the next pass, so it only makes sense inside for, while and do-while. A switch has no passes of its own, so writing continue in a bare switch body is a compile error. If that switch happens to sit inside a loop, then continue applies to the loop and simply leaves the switch behind. The statement meant for leaving a switch is break.
प्रश्न 4उत्तर + हल
निम्नलिखित लूप कब तक चलेगा?
for (x=0; x=3; x++)
How long does the following loop last?
for (x=0; x=3; x++)
Aतीन बारthree times
Bचार बारfour times
Cहमेशाforever
Dकभी नहींNever
सही उत्तर / Answer: (C)
हल / Solution
यहाँ शर्त के खाने में तुलना x == 3 नहीं, बल्कि निर्धारण (assignment) x = 3 लिखा है। C में निर्धारण का अपना मान वही होता है जो दाहिनी ओर रखा गया है, यानी तीन, और शून्य से अलग हर मान सच गिना जाता है। इसलिए शर्त हर चक्कर में सच मिलती है और लूप कभी नहीं रुकता। x++ चलता रहता है पर शर्त उसे देखती ही नहीं, सो तीन या चार बार वाले विकल्प ग़लत हैं।
The condition slot does not hold the comparison x == 3 but the assignment x = 3. In C an assignment itself has a value, namely the value placed on its right, which is three here, and every value other than zero counts as true. So the condition is true on every pass and the loop never stops. x++ keeps running but the condition never looks at it, which rules out three times, four times and never.
प्रश्न 5उत्तर + हल
SWITCH कथन के नियंत्रक कथन (controlling statement) का डेटा प्रकार किस प्रकार का नहीं हो सकता?
Data type of the controlling statement of a SWITCH statement cannot be of the type:
Aint
Bchar
Cshort
Dfloat
सही उत्तर / Answer: (D)
हल / Solution
switch जिस व्यंजक पर चलता है वह पूर्णांक जाति (integral type) का होना ज़रूरी है — int, short, long, char या enum। char भी भीतर से छोटा पूर्णांक ही है, सो वह चलता है। float और double दशमलव वाले प्रकार हैं और उनमें बराबरी की जाँच भरोसेमंद नहीं होती, इसलिए C मानक उन्हें switch में मना करता है और कंपाइलर साफ़ त्रुटि देता है। इसी कारण यहाँ सही उत्तर float है।
The expression a switch runs on must be of an integral type: int, short, long, char or an enum. A char is itself a small integer inside, so it is allowed. float and double are fractional types and equality testing on them is never reliable, so the C standard does not permit them in a switch and the compiler reports a clear error. That is why float is the answer here.
प्रश्न 6उत्तर + हल
_______ में दो लूपों के शरीर को मिलाकर एक लूप बना दिया जाता है, बशर्ते वे एक-दूसरे को ही संदर्भित न कर रहे हों।
In _______, the bodies of the two loops are merged together to form a single loop provided that they do not make only references to each other.
ALoop unrolling
BStrength reduction
CLoop concatenation
DLoop jamming
सही उत्तर / Answer: (D)
हल / Solution
एक ही सीमा पर चलने वाले दो अलग लूपों को जोड़कर एक लूप बना देना «लूप जैमिंग» (loop jamming) कहलाता है; इसे लूप फ्यूज़न भी कहते हैं और इससे लूप का ऊपरी ख़र्च घटता है। लूप अनरोलिंग (loop unrolling) में शरीर की नक़लें बनाकर चक्करों की गिनती घटाई जाती है। स्ट्रेंथ रिडक्शन (strength reduction) में महँगी गुणा की जगह सस्ता जोड़ रखा जाता है। «लूप कंकैटिनेशन» कोई मानक अनुकूलन ही नहीं है।
Merging two separate loops that run over the same range into a single loop is called loop jamming, also known as loop fusion; it cuts down the overhead of running the loop twice. Loop unrolling instead copies the body so that fewer passes are needed. Strength reduction replaces a costly multiplication with cheaper addition. Loop concatenation is not a standard optimisation name at all, so it only works as a distractor here.
प्रश्न 7उत्तर + हल
C में «break» तथा «continue» कथनों के संदर्भ में सबसे सही कथन चुनिए।
In the context of "break" and "continue" statements in C, pick the best statement.
A«break» और «continue» दोनों for, while, do-while के शरीर में तथा switch के शरीर में चल सकते हैं"break" and "continue" can be used in "for", "while", "do-while" loop body and "switch" body
B«break» और «continue» दोनों for, while, do-while के शरीर में चल सकते हैं, पर switch के शरीर में सिर्फ़ «break» चल सकता है"break" and "continue" can be used in "for", "while", "do-while" loop body but only "break" can be used in "switch" body
C«break» और «continue» for, while तथा do-while के शरीर में चल सकते हैं, और इनके अलावा «continue» तथा «break» switch एवं «if-else» के शरीर में भी चल सकते हैं"break" and "continue" can be used in "for", "while" and "do-while" loop body besides, "continue" and "break" can be used in "switch" and "if-else" body
D«break» for, while तथा do-while के शरीर में चल सकता है"break" can be used in "for", "while" and "do-while" loop body
सही उत्तर / Answer: (B)
हल / Solution
break तीनों लूप — for, while, do-while — और switch, चारों जगह चलता है; switch में वही एक-एक case को अलग करता है। continue का काम है «बचा हिस्सा छोड़कर अगला चक्कर शुरू करो», जो सिर्फ़ लूप में अर्थ रखता है, सो अकेले switch के शरीर में लिखने पर कंपाइलर त्रुटि देता है। इसी से दूसरा विकल्प सही है। पहला continue को switch में भी जायज़ बताता है और चौथा continue छोड़ ही देता है।
break works in all three loops, for, while and do-while, and in switch as well, where it separates one case from the next. continue means skip the rest of this pass and start the next one, which makes sense only inside a loop, so writing it in a bare switch body is a compile error. That makes the second option right. The first allows continue in switch, the third adds if-else, and the fourth drops continue altogether.
प्रश्न 8उत्तर + हल
इस C कोड का आउटपुट क्या है?
int main()
{
int i = 0, j = 0;
while (i < 5, j < 10)
{
i++;
j++;
}
printf("%d, %d\n", i, j);
}
What is the output of this C code?
int main()
{
int i = 0, j = 0;
while (i < 5, j < 10)
{
i++;
j++;
}
printf("%d, %d\n", i, j);
}
A5, 5
B5, 10
C10, 10
DSyntax error
सही उत्तर / Answer: (C)
हल / Solution
while की शर्त में अल्पविराम संचालक (comma operator) लगा है। यह संचालक बाएँ भाग को जाँचकर उसका नतीजा फेंक देता है और पूरे व्यंजक का मान सिर्फ़ दाहिने भाग से तय होता है, यानी यहाँ शर्त केवल j < 10 है। इसलिए i < 5 का कोई असर नहीं पड़ता और लूप j के दस होने तक चलता है; साथ-साथ i भी दस तक बढ़ जाता है। छपाई «10, 10» आती है और वाक्य-रचना वैध है।
The while condition uses the comma operator. It evaluates the left part, throws that result away, and the value of the whole expression comes only from the right part, so the real condition here is just j < 10. The test i < 5 therefore has no effect, the loop runs until j reaches ten, and i climbs to ten alongside it. The output is 10, 10 and the syntax is perfectly legal.
प्रश्न 9उत्तर + हल
C में पुनरावृत्ति (iteration) का उदाहरण है —
Example of iteration in C.
Afor
Bwhile
Cdo-while
Dउपरोक्त सभीAll of the mentioned
सही उत्तर / Answer: (D)
हल / Solution
पुनरावृत्ति (iteration) का अर्थ है एक ही कथन-समूह को बार-बार चलाना, और C में इसके तीन रूप हैं — for, while तथा do-while। for तब सुविधा देता है जब चक्कर की गिनती पहले से तय हो। while शर्त पहले जाँचता है, इसलिए शरीर शून्य बार भी चल सकता है। do-while शरीर एक बार चलाकर बाद में शर्त देखता है, सो वह कम-से-कम एक बार चलता ही है। तीनों लूप हैं, इसलिए «उपरोक्त सभी» सही है।
Iteration means running the same group of statements again and again, and C offers three forms of it: for, while and do-while. A for loop suits the case where the number of passes is known in advance. A while loop tests its condition first, so the body may run zero times. A do-while loop runs the body once and tests afterwards, so it always runs at least once. All three are loops, so All of the mentioned is right.
प्रश्न 10उत्तर + हल
इस प्रोग्राम का आउटपुट क्या है?
int main() {
int i;
for ( i=0; i<5; i++ )
{
i = 10;
printf ( "%d ", i );
}
return 0;
}
What is the output of this program?
int main() {
int i;
for ( i=0; i<5; i++ )
{
i = 10;
printf ( "%d ", i );
}
return 0;
}
A10 10 10 10 10
B10 11 12 13
C10
DCompilation Error
सही उत्तर / Answer: (C)
हल / Solution
पहले चक्कर में i शून्य है, पर लूप के भीतर पहुँचते ही उसे दस कर दिया जाता है, सो printf दस छापता है। चक्कर पूरा होने पर i++ चलता है और i ग्यारह हो जाता है; अब शर्त i < 5 झूठी पड़ जाती है और लूप वहीं रुक जाता है। यानी छपाई एक ही बार होती है। पाँच बार या बढ़ती गिनती वाले विकल्प तभी बनते जब भीतर मान बदला न जाता।
On the first pass i is zero, but the body immediately sets it to ten, so printf prints ten. At the end of the pass i++ makes i eleven, the condition i < 5 now fails and the loop stops there. So the printing happens only once. The repeated row and the increasing sequence would appear only if the body did not overwrite i, and the code itself compiles without any error.
आगे के 20 प्रश्नों के उत्तर और हल app मेंFliQi Question Bank — अभ्यास, हल और आपकी प्रगति