Hi all,
Can anyone explain to me in details preferable with an example the different between i++ and i++ please.
Here my example with what I understood:
for (int (0); i<10; i++) {
cout << i++;
cout << ++i;
}
What is the output?
Is the working steps like this:
When i =0;
for (i = 0; 0 < 10; 0) //True 0 <10 do the following
output: 0 //0 + 1
output: 2 //1 + 1
When i =2;
for (i = 2; 2 < 10; 2) //True 2 <10 do the following
output: 2 //2 + 1
output: 4 //3 + 1
When i =4;
for (i = 4; 4 < 10; 4) //True 4 <10 do the following
output: 4 //4 + 1
output: 6 //5 + 1
When i =6;
for (i = 6; 6 < 10; 6) //True 6 <10 do the following
output: 6 //6 + 1
output: 8 //7 + 1
When i =8;
for (i = 8; 8 < 10; 8) //True 8 <10 do the following
output: 8 //9 + 1
output: 11 //10 + 1
So the output would be: 022446811
Can anyone please help me if this is a correct output.
Thanks