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 Posted / 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 View All Answers
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
Why is a semicolon (;) put at the end of every program statement?
What is operator promotion?
How can I open files mentioned on the command line, and parse option flags?
How are strings stored in c?
Is c is a middle level language?
What is a static function in c?
What is use of bit field?
What is the size of empty structure in c?
What are dangling pointers? How are dangling pointers different from memory leaks?
What is a lvalue
Write a code on reverse string and its complexity.
Why void main is used in c?
What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file
What is call by value in c?