-
Consider the following C Program.
#include
int. main () {
int m = 10;
int n, n1;
n = ++m;
n1 = m++;
n – –;
– – n1;
n – = n1;
printf (“%d”, n);
return 0;
}
The output of the program is _________.
-
- 0
- 1
- 2
- 3
Correct Option: A
Consider each statement in the program
(1) int m = 10; //m = 10
(2) int n, n1; (3) n = + + m; //n = 11
(n = (++m)) will increment by m and it assign to n:
(n = 11, m = 11)
(4) n1 = m++; //n = 11
n1 = m++; will assign (m) to (n1) and then increment m by one.
So, (n1 = 11), (m = 12)
(5) n– –; //n = 10
(n - -), decremented by 1 then (n = 10).
(6) - - n1; //n1 = 10
(- - n1) decremented by 1 then (n1 = 10)
(7) n - = n1; //n = 0
(n- = n1), same as n = (n – n1) = 10 – 10 = 0
(8) Print f ("%d", n);
Then, the output will be 0.
Hence, 0 is correct answer.