A

Admin • 833K Points
Coach

Q. What will be the output of the following code?

Code:
#include <stdio.h>
int main() {
int i = 0;
for(i = 0; i < 3; i++) {
static int x = 0;
x++;
printf("%d ", x);
}
return 0;
}
  • (A) 1 1 1
  • (B) 1 2 3
  • (C) 0 1 2
  • (D) Error
  • Correct Answer - Option(B)
  • Views: 26
  • Filed under category C Programming
  • Hashtags:

Explanation by: Admin

Static variables retain their value between function calls/iterations.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.