Machine-translated by Google. Questions are authored in English.
Top

Discussion

What is the output of the following program?

#include <stdio.h>

int main()
{
static int a = 3;
printf("%d", a--);
return 0;
}

 

  • A.1
  • B.2
  • C.3

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.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.