main()
{int i=5; // line 1
i=(++i)/(i++); // line 2
printf("%d",i); // line 3
} output is 2 but if we replace line 2 and line 3 by
printf("%d",i=(++i)/(i++)); then output is 1. Why?



main() {int i=5; // line 1 i=(++i)/(i++); // line 2 printf("%d",i); // line 3 } output..

Answer / gagandeep bansal

working of incr/decr operator:first pre operators then
rest of operators then post operators

so,2 line become:i=6/(5++); /*pre operator*/
i=6/5=1; /*rest of operators*/
now post incr operator will work so,i=2; /*post operator*/
so output is 2.
in second case:i=6/(5++); /*pre operator*/

i=6/5==1; /*rest of operators*/

now post incr operator will work so,i=2;
again i=3/(2++);
i=1;
so,output is 1.
becouse in case of post operators first assign then
incr/decr.

Is This Answer Correct ?    9 Yes 3 No

Post New Answer

More C Interview Questions

Is it possible to use curly brackets ({}) to enclose single line code in c program?

0 Answers  


Which is better malloc or calloc?

0 Answers  


convert 0.9375 to binary

2 Answers   CTS, TANCET,


What are the different properties of variable number of arguments?

0 Answers  


Explain continue keyword in c

0 Answers  


What does c in a circle mean?

0 Answers  


what is answer for perfect number????????????????

1 Answers  


How do you generate random numbers in C?

0 Answers  


What is a floating point in c?

0 Answers  


What is dangling pointer in c?

0 Answers  


What is the best organizational structure?

0 Answers  


Why does everyone say not to use scanf? What should I use instead?

0 Answers  


Categories