void main()
{
int i=5,y=3,z=2,ans;
clrscr();
printf("%d",++i + --z + i++ + --i * ++y);
i=5,y=3,z=2;
ans=++i + --z + i++ + --i * ++y;
printf("\n%d",ans);
getch();
}

Its output is 37 and 31....
Please explain me why its different
How it works.....

Answers were Sorted based on User's Feedback



void main() { int i=5,y=3,z=2,ans; clrscr(); printf("%d",++i + --z + i++ + --i * ++..

Answer / ram mohan

Ur approach may correct but I have a small dought
Plz tell me output of
Printf("", ++i + --z +i + --i * ++y) ;
@pawanjhi

Is This Answer Correct ?    0 Yes 0 No

void main() { int i=5,y=3,z=2,ans; clrscr(); printf("%d",++i + --z + i++ + --i * ++..

Answer / pawanjha12

here in first statement

printf("%d",++i + --z + i++ + --i * ++y);

argument is : ++i + --z + i++ + --i * ++y.

first it will maintain stack operation like

++y (now fifth, it will execute and, y=4)(top 4)
--i (now fourth, it will execute and, i=6)
(because, last value of i were 7, once i++ were
executed, now --i will less one value in i)(top 3)
i++ (now third, it will execute and, i=6, it will
as it is, its value will for next stack value.)
(top 2)
--z (now second, it will execute and, z=1)(top 1)
++i (first it will execute and, i=6)(top 0)

now (++i + --z + i++ + --i * ++y)
(6+1+6+6*4)=(37)

it is output, say 37,for this printf("%d",++i + --z + i++
+ --i * ++y);

.................................................

Now Let me go with second statement, that is :

ans=++i + --z + i++ + --i * ++y;

here,
first of all ++y will contain the value of variable y=4
++y=4

after this, --i will less the value of variable i, say now
i = 4,
(--i=4),

after this, i++ will execute and, it will not increase the
value of variable i, right now, so value of i, say now i =
4, as it is.

after this, --z will less the value of variable z, say now
z = 1,
(--z=1)

now, ++i will increase the value of variable i.
Say i = 5.
.......................................................

now value of valiable i in memory is 5.
ans=5+1+5+5*4
ans=5+1+5+20
ans=31..........,
still if you are not getting, so come to me at
pankajace12@gmail.com

Is This Answer Correct ?    1 Yes 5 No

Post New Answer

More C C++ Errors Interview Questions

Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .

2 Answers  


what is exceptions?

5 Answers   HCL, Wipro,


To generate the series 1+3+5+7+... using C program

18 Answers  


A sample program using data structure? what is file handling?

0 Answers   TCS,


How to reverse a linked list without using array & -1? Thank you.

2 Answers   Access, Satyam,


main() { char c; for(c='A';c<='Z';c++) getch(); }

9 Answers  


what are the techniques for reducing the fragility of a memory bug?

1 Answers  


How to create a program that lists the capital country when told what the original country is? (Terribly sorry, I'm a novice programmer and would appreciate any help ;). Cheers, Alexxis

0 Answers  


what is the error in the following code: main() { int i=400,j; j=(i*i)/i; }

4 Answers  


Display this kind of output on screen. 1 0 1 1 0 1 3. Display this kind of output on screen. 1 1 0 1 0 1 4. Display this kind of output on screen. 1 1 0 1 0 1 5.Display this kind of output on screen. 1 2 3 4 5 6 7 8 9 10

1 Answers  


WHAT WILL BE THE OUTPUT OF THE FOLLOWING QUESTION void main() { int x=4,y=3,z; z=x-- -y; printf("%d%d%d",x,y,z); }

25 Answers   HCL,


void main() { int i=1; printf("%d%d%d",i,++i,i++); } Cau u say the output....?

24 Answers   HCL,


Categories