-
Which of the following is the correct output for the program given below?
#include <stdio.h>
int main ( )
{
int a = 9, b, c;
b = --a;
c = a--;
printf ( "%d %d %d\n", a, b, c);
return 0;
}
-
- 9 8 8
- 9 8 7
- 8 8 7
- 7 8 8
- 7 7 8
Correct Option: D
Step 1: int a=9, b, c; here variable a, b, c are declared as an integer type and variable a is initialized to 9.
Step 2: b = --a; becomes b = 8; because (--a) is pre-decrement operator.
Step 3: c = a--; becomes c = 8;. In the next step variable a becomes 7, because (a--) is post-decrement operator.
Step 4: printf("%d, %d, %d\n", a, b, c); Hence it prints "7 8 8".