EmbLogic's Blog

problem in execution

#include
int main()
{
int i=1;
printf(“%d%d%d%d%d”,i,++i,i++,++i,++i);
return 0;
}
what wil be the output with reason?

4 Responses to problem in execution

  1. arjumand says:

    the output should be 5 5 5 5 5

    but i know it will be incorrect for one of the operators for sure ;)

  2. hemant.kumar says:

    your output should be 5 5 3 5 5
    1st step: your execution will start from right to left.
    2nd step:remember this point when you use PRE INCREEMENT operator i.e (++i) ,it takes the last updated value of i

    for example..
    let i=1;
    printf(“%d %d %d %d \n”,++i,++i,++i,++i);
    your output would be 5 5 5 5
    because the last updated value in i is 5;

    and in your case
    i=1;
    prntf(“%d %d %d %d %d\n”,i,++i,i++,++i,++i)
    taking from the right side
    2
    3
    3
    5
    5(last updated value is 5)
    so wherever you have declared the ++i operator replace it with 5 but in case of post increement operator (i++)it would be 3

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>