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?
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 |
Can you please compare array with pointer?
Which of the following operators is incorrect and why? ( >=, <=, <>, ==)
What is the best way to store flag values in a program?
array of pointer pointer to array pointer to pointer
What is a wrapper function in c?
How can I convert integers to binary or hexadecimal?
write a program to print infinte number
What is an anonymous union and where to apply that ?
what are non standard function in c
write function to reverse char array ... without using second array
Why doesn't the code "int a = 1000, b = 1000; long int c = a * b;" work?
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