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 are two categories of clint-server application development ?

1 Answers  


Can you think of a way when a program crashed before reaching main? If yes how?

2 Answers  


5) Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.without using big int and exponential function

1 Answers   TCS,


Is malloc memset faster than calloc?

0 Answers  


main() {int a=200*200/100; printf("%d",a); }

14 Answers   TCS,






Write a c program to read a positive number and display it in words.? ex: 123=one two three help me....

2 Answers  


What are pointers?

0 Answers   Accenture, Tavant Technologies, Zensar,


2. What is the function of ceil(X) defined in math.h do? A)It returns the value rounded down to the next lower integer B)it returns the value rounded up to the next higher integer C)the Next Higher Value D)the next lower value

3 Answers   Accenture,


4.weight conversion: Write a program that will read weight in pounds and convert it into grams.print both the original weight and the converted value.There are 454 grams in a pound.design and carry out a test plan for this program.

1 Answers   Wipro,


What is the difference between printf and scanf )?

0 Answers  


What is a method in c?

0 Answers  


What are the features of the c language?

0 Answers  


Categories