15,389,740 members
See more:
I have confusion with i++ and ++i .
Please any one help me.
Posted

## Solution 2

If you are not sure about expressions then you should spend time studying the documentation[^]. It is important to get these concepts fixed in your mind.

## Solution 1

First case
C++
```int i = 10;
int j = i++;```

After execution value of i would be 11 and value of j would be 10.
As this operator is POSTincrement , increament will be done AFTER the assignement.

Second case
C++
```int i = 10;
int j = ++i;```

After execution value of i would be 11 and value of j would be 11.
As this operator is PREincrement , increament will be done BEFORE the assignement.
v2
Nisarg S Shah 19-Jul-12 5:12am

I think that "i would be 11 and value of j would be 10." and "i would be 11 and value of j would be 11." should be highlighted along with AFTER and BEFORE.
PrafullaVedante 20-Jul-12 2:54am

Done :)

## Solution 3

hi

once lookat this

C#
```string[] items = {"a","b","c","d"};
int i = 0;
foreach (string item in items)
{
Console.WriteLine(++i);
}
Console.WriteLine("");

i = 0;
foreach (string item in items)
{
Console.WriteLine(i++);
}```

output will be

C#
```1
2
3
4

0
1
2
3```

i hope it helps you...

Thanks&&Regards
Sandeep

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Richard MacCutchan 125 OriginalGriff 115 0x01AA 75 Gerry Schmitz 55 Patrice T 45
 OriginalGriff 990 Richard MacCutchan 500 0x01AA 265 Gerry Schmitz 220 Maciej Los 190

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900