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
How many levels deep can include files be nested?
How the c program is executed?
How variables are declared in c?
What is difference between %d and %i in c?
Is array name a pointer?
What is "Duff's Device"?
What is meant by errors and debugging?
How many types of errors are there in c language? Explain
Is using exit() the same as using return?
Explain output of printf("Hello World"-'A'+'B'); ?
What is the general form of a C program?
Explain the properties of union. What is the size of a union variable
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 ].
What is huge pointer in c?
What is the difference between volatile and const volatile?