Answer to Question #266935 in C for anubhav

Question #266935

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;


1
Expert's answer
2021-11-16T05:21:17-0500

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.




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS