Difference between (i++) and (++i) in C# !!

20 Jan

Look at the following code segment:

int x = 5;
int y = 10;

int a = x++;
int b = ++y;

If you check the result of a and b, they will be as following:

a = 5
b = 11

i++ means ‘tell me the value of i, then increment’

++i means ‘increment i, then tell me the value’

They are pre-increment, post-increment operators. In both cases the variable is incremented, but if you were to take the value of both expressions in exactly the same cases, the result will differ.

Leave a comment

Posted by on January 20, 2013 in Visual C# . NET


Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: