1. (a) What will be the output for the following program C code?
#include<stdio.h>
int main()
{
int a=12, b=4, c;
++a;
b++;
c=a++ - b;
printf(“ %d %d %d\n ”, a, b, c);
return 0;
Output
14 5 8
Explanation
a
The initial value of a is 12. The statement ++a; increases the the value of a to 13.
The statement c=a++ - b; increases the value of a to 14. Therefore the final value of a is 14.
b
The initial value of a is 4. The statement b++; increase the the value of b to 5. Therefore the final value of b is 5.
c
The statement c=a++ - b; uses the previous value of a which is 13, subtract the value of b (5) from it before increasing the value of a. the result is then assigned to c.
Therefore the value of c=13-5 which is equal to 8.
Comments
Leave a comment