Jump to content

increment operator weirdness in these situations

Featured Replies

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

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

Look at the difference in the output in the last example. Why is that different from the others?

Archived

This topic is now archived and is closed to further replies.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.