EmbLogic's Blog

issue in pre and post increment?????????????

int x=3,y;
y=(++x*++x*++x)/++x;
the value of y=21and x=7

why?????????????????

int x=3,y;
y=(x++*x++*x++)/x++;
the value of y=9 and x=7

why?????????????????

 

2 Responses to issue in pre and post increment?????????????

  1. manoj says:

    hi..

    ++x * ++x * ++x will be 150 .
    take it like this…
    ((++x*++x)*++x) then divide it with 7.. u’ll get 21.. AND

    post increment doesn’t make any effect in expression.. it only increase all the values at the end of expression.. thats why.. y=9 and at the end of expression x=7(Incremented later on, after division)

    Cheers !!

  2. amit yadav says:

    In pre firstly increment the x and in first multiply the x maxm value is used 5 and output 25 thn increment 6 mul 150…further increase x value 7 thn divide…

    In post the x value is same .in last x value increment.

Leave a Reply to amit yadav Cancel 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>