Jump to content

Recommended Posts

Posted

can someone explain to me the outputs please?

i don't understand how the increment and decrement operator work in these situations.

thanks

post-98344-0-05276300-1373409017_thumb.png

post-98344-0-39295700-1373409020_thumb.png

post-98344-0-22134300-1373409024_thumb.png

post-98344-0-80367700-1373409028_thumb.png

Posted

i=1;

x=++i; /* x=2 because increment before the value of i is assigned to x */

x=i++; /* x=2 because increment after the value of i is assigned to x */

 

++i increment before value of i used in expression preincrement

i++ increment after value of i used in expression postincrement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.