Can someone explain:
int y=10;
printf(“%d %d %d”,++y,y,++y);
answer is:
12 12 12
Can someone explain:
int y=10;
printf(“%d %d %d”,++y,y,++y);
answer is:
12 12 12
EmbLogic Research & Competency Development Labs
Phone: +91 9818467776, 8527567776, 9650467776
Email: info@emblogic.com
Copyright © EmbLogic Embedded Technologies Pvt. Ltd.
Since, int y=10 is local variable.so it will be store in stack.
we know that stack is first-in-last-out.
According to this rule, y will be store in stack from left to right, and output will be come from right to left.
in that case too, output should be
12 11 11
isn’t it?
can you explain how your explanation output as above?
since, y=10 then ++y pre-incremented of y =11, ie y=10 replaced with y=11, then y ie y=11, again it incremented ++y=12, ie y=11 replaced with y=12. and finally print value of y 3-times.
It means, ++y just increment the value of y and replaced it with new value.
operator precedence is
postincrement
preincrement
normal variable
and evaluated from right to left
do this