Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 1 : 9 9 9

Advertisement

Detailed Solution

सही उत्तर 9 9 9 है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following C program? void f(int n) { static int s = 0; if (n > 0) { s += n; f(n - 2); printf("%d ", s); } } int main() { f(5); } / निम्नलिखित C प्रोग्राम का आउटपुट क्या है?

1.
9 9 9
2.
5 8 9
3.
9 8 5
4.
15 8 5

Correct Answer: 9 9 9

The static variable s is shared across all calls: it becomes 5, then 8, then 9 as the recursion descends. Each printf executes during unwinding, when s is already 9, so "9 " is printed three times. / static चर s सभी कॉलों में साझा होता है: पुनरावृत्ति के उतरते समय यह 5, फिर 8, फिर 9 हो जाता है। प्रत्येक printf वापसी के समय चलता है, जब s पहले से 9 है, इसलिए "9 " तीन बार प्रिंट होता है।

Downloaded from PrepSnap (prepsnap.in)