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

WHAT IS PRE POSSESSORS?

6 Answers   TATA,


Is there anything like an ifdef for typedefs?

0 Answers  


What are global variables?

0 Answers  


how can i print "hello".please consider inverted commas as well.i want to print on console: "hello"

4 Answers   Wipro,


I came across some code that puts a (void) cast before each call to printf. Why?

0 Answers  






to get a line of text and count the number of vowels in it

3 Answers   Satyam,


1 1 12 21 123 321 12344231 how i creat it with for loop??

1 Answers  


What is the memory allocated by the following definition ? int (*x)();

2 Answers   ADITI,


which of the function operator cannot be over loaded a) <= b)?: c)== d)*

10 Answers   Cisco, CTS, Google, HCL, HP,


Why should I use standard library functions instead of writing my own?

0 Answers  


Is it possible to run using programming C for Java Application?

2 Answers   NIC,


/*program to calculate hra,da in salary if salary less than 10000 then hra15%,da13% otherwise hra20%,da18%/*

6 Answers  


Categories