How many times 'save trees' will be displayed by C++ loop? do { cout << "save…
2022
How many times 'save trees' will be displayed by C++ loop? do { cout << "save trees"; } while(0);
- A.
One
- B.
three
- C.
Two
- D.
Zero
Attempted by 173 students.
Show answer & explanation
Correct answer: A
In a do-while loop, the body executes at least once before the condition is checked.
Here, the loop body runs once, printing 'save trees'.
After execution, the condition while(0) is evaluated. Since 0 is false, the loop terminates.
Thus, 'save trees' is printed exactly once.
हिन्दी उत्तर:
डो-वाइल लूप में, शर्त की जाँच करने से पहले बॉडी कम से कम एक बार चलती है।
यहाँ, लूप बॉडी एक बार चलती है और 'save trees' प्रिंट करती है।
चलने के बाद, शर्त while(0) का मूल्यांकन किया जाता है। चूँकि 0 गलत है, लूप समाप्त हो जाता है।
इसलिए, 'save trees' ठीक एक बार प्रिंट किया जाता है।