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

How can I run c program?

0 Answers  


Where static variables are stored in c?

0 Answers  


What is s in c?

0 Answers  


#include<stdio.h> int main() { int i=0,j=1,k=2,m,n=0; m=i++&&j++&&k++||n++; printf("%d,%d,%d,%d,%d",i,j,k,m,n); }

12 Answers   Capital IQ, Sasken,


Give me the code of in-order recursive and non-recursive.

0 Answers   DELL,






How to access or modify the const variable in c ?

16 Answers   HCL, HP,


FILE PROGRAMMING

0 Answers   Wipro,


You have an int array with n elements and a structure with three int members. ie struct No { unsigned int no1; unsigned int no2; unsigned int no3; }; Point1.Lets say 1 byte in the array element is represented like this - 1st 3 bits from LSB is one number, next 2 bits are 2nd no and last 3 bits are 3rd no. Now write a function, struct No* ExtractNos(unsigned int *, int count) which extracts each byte from array and converts LSByte in the order mentioned in point1.and save it the structure no1, no2, no3. in the function struct No* ExtractNos(unsigned int *, int count), first parameter points to the base address of array and second parameter says the no of elements in the array. For example: if your array LSB is Hex F7 then result no1 = 7, no2 = 2, no3 = 7. In the same way convert all the elements from the array and save the result in array of structure.

2 Answers   Qualcomm,


write a program to generate 1st n fibonacci prime number

12 Answers  


What is a C array and illustrate the how is it different from a list.

1 Answers   Amazon,


Tell me when would you use a pointer to a function?

0 Answers  


Is c language still used?

0 Answers  


Categories