What is the output of the following program?
#include <stdio.h>
int main()
{
static int a = 3;
printf("%d", a--);
return 0;
}
Answer: C
Correct answer: 3
a-- is a post-decrement: the current value is what the expression yields, and the decrement happens afterwards. So printf receives 3; a becomes 2 immediately after, but nothing prints it. The static qualifier matters only if the function is called again.
Please log in or register to report this question.