EmbLogic's Blog

increments in printf

Can someone explain:

int y=10;
printf(“%d %d %d”,++y,y,++y);

answer is:
12 12 12

5 Responses to increments in printf

  1. Anil says:

    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.

  2. operator precedence is

    postincrement
    preincrement
    normal variable

    and evaluated from right to left

    do this

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>