Question

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

Option 3 : 013

Advertisement

Detailed Solution

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

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following C code? #include <stdio.h> int main(){ int i; for(i=0;i<3;i++){ static int s=0; s+=i; printf("%d",s); } return 0; } / निम्नलिखित C कोड का आउटपुट क्या है? #include <stdio.h> int main(){ int i; for(i=0;i<3;i++){ static int s=0; s+=i; printf("%d",s); } return 0; }

1.
012
2.
123
3.
013
4.
036

Correct Answer: 013

The static variable s is initialized once and retains its value across iterations: i=0 -> s=0, i=1 -> s=1, i=2 -> s=3, printing "013". Option (a) is the trap of treating s as an ordinary automatic variable. / स्टैटिक चर s एक बार प्रारंभ होता है और पुनरावृत्तियों में अपना मान बनाए रखता है: i=0 -> s=0, i=1 -> s=1, i=2 -> s=3, "013" प्रिंट होता है। विकल्प (a) s को सामान्य ऑटोमैटिक चर मानने का जाल है।

Downloaded from PrepSnap (prepsnap.in)