Question 1
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
for (int i = 0; i < 3; i++) {
static int s = 0;
int a = 0;
s++;
a++;
printf("%d%d ", s, a);
}
printf("\n");
return 0;
}
- A 11 21 31 Correct
- B 11 11 11
- C 11 22 33
- D 01 11 21
Correct Answer: Option A
The static s is initialised once and keeps counting. The automatic a is created and set to 0 on every pass of the loop body, so it is always 1 after a++.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!