EmbLogic's Blog

Behaviour of printf function

int i=0;
printf(“%d\t%d\t%d\t%d\t%d\t%d\t%d\n”,i++,++i,i++,++i,i,i++,i);

What will be the output? And how?

2 Responses to Behaviour of printf function

  1. amritpreet says:

    In case of printf always compute the output from right to left but print from left to right…
    Second point to be noted while computing is that i++ is first printed immediately and then computed while in case of ++i, it is computed first and prints the final value of i in the end. i behaves similar to ++i in printing…

  2. amritpreet says:

    output will be
    4 5 2 5 5 0 5

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>