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
How to throw some light on the b tree?
What does == mean in texting?
What are the different categories of functions in c?
What is the difference between array and structure in c?
Write a program to print “hello world” without using semicolon?
#define PRINT(int) printf("int = %d ",int) main() {< BR> intx,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }
What is the use of a ‘ ’ character?
When should structures be passed by values or by references?
The process of repeatedly running a set of computer instructions until some condition is specifed a) condition b) sequential condition c) global d) iteration
What are comments and how do you insert it in a C program?
#include
What 'lex' does?
What are variables and it what way is it different from constants?
number of times a digit is present in a number
What is meant by inheritance?