Question discussion

What is the output of the following C program?#include void count() { static int c = 0; int d = 0; c++; d++; printf("%d%d ", c, d); } int m…

1308Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
void count() {
    static int c = 0;
    int d = 0;
    c++; d++;
    printf("%d%d ", c, d);
}
int main() {
    count(); count(); count();
    return 0;
}
  • A11 21 31
  • B11 11 11
  • C11 22 33
  • D11 12 13
Correct answer: A

Explanation

The static variable c keeps its value between calls (1, 2, 3) while the automatic variable d is re-initialised to 0 and becomes 1 every time.

Discussion 0

Nobody has replied yet. Start the discussion!