main()
{ int i=5;
printf("%d",++i + i);

} output is 10

------------------------
main()
{ int i=5;
printf("%d",i++ + i);

}output is 12
why it is so? give appropiate reason....

Answer Posted / sudarsan.tuku@gmail.com

1>On the 1st que the ans. is 12
bcz perform the pre increment 1st then add them.
After the pre increment the value of i becomes 6 and
then it perform the add operation i.e. i+i=6+6=12.

2>output is 10
It 1st perform the pre operation but there is no pre
operation in the que.
2ndly it perform the operation i.e i+i=5+5=10.
3rdly it perform post operation i.e i++ so i becomes 6.
but here the output is 10.

Is This Answer Correct ?    16 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many levels deep can include files be nested?

642


How the c program is executed?

624


How variables are declared in c?

565


What is difference between %d and %i in c?

684


Is array name a pointer?

597






What is "Duff's Device"?

695


What is meant by errors and debugging?

639


How many types of errors are there in c language? Explain

560


Is using exit() the same as using return?

666


Explain output of printf("Hello World"-'A'+'B'); ?

967


What is the general form of a C program?

593


Explain the properties of union. What is the size of a union variable

710


Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].

634


What is huge pointer in c?

573


What is the difference between volatile and const volatile?

556