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

Can you please compare array with pointer?

0 Answers  


Which of the following operators is incorrect and why? ( >=, <=, <>, ==)

0 Answers  


What is the best way to store flag values in a program?

0 Answers  


array of pointer pointer to array pointer to pointer

1 Answers   MAHINDRA,


What is a wrapper function in c?

0 Answers  






How can I convert integers to binary or hexadecimal?

2 Answers  


write a program to print infinte number

4 Answers  


What is an anonymous union and where to apply that ?

3 Answers   HP,


what are non standard function in c

0 Answers  


write function to reverse char array ... without using second array

3 Answers  


Why doesn't the code "int a = 1000, b = 1000; long int c = a * b;" work?

7 Answers  


how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions

0 Answers  


Categories