Consider the following C program.
#include<stdio.h>
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 ______
View worked solution
Answer: 0
Let us trace the execution of the program step-by-step:
- Initialization:
m = 10 - Statement:
n = ++m;
This is a pre-increment operation.mis incremented first:m = 11- Then, the incremented value is assigned to
n:n = 11
- Statement:
n1 = m++;
This is a post-increment operation.- The current value of
m(which is 11) is assigned ton1:n1 = 11 - Then,
mis incremented:m = 12
- The current value of
- Statement:
n--;
Decrementnby 1:n = 11 - 1 = 10 - Statement:
--n1;
Decrementn1by 1:n1 = 11 - 1 = 10 - Statement:
n -= n1;
This is equivalent ton = n - n1:n = 10 - 10 = 0
The printf statement prints the final value of n, which is 0.
Free practice · Your answers on this page are not saved.
