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


Please Help Members By Posting Answers For Below Questions

Write a Program to find whether the given number or string is palindrome.

591


Not all reserved words are written in lowercase. TRUE or FALSE?

701


Explain the use of #pragma exit?

669


What is %s and %d in c?

565


Explain how do you determine a file’s attributes?

572






Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

2538


shorting algorithmS

1771


Why we use int main and void main?

522


Which header file is used for clrscr?

548


What is the symbol indicated the c-preprocessor?

669


Is c easier than java?

547


How will you declare an array of three function pointers where each function receives two ints and returns a float?

747


Place the #include statement must be written in the program?

535


What is define directive?

613


Synonymous with pointer array a) character array b) ragged array c) multiple array d) none

591