## mythili_sharon

i need the difference between i++ and ++i, where is i++ used and where ++i is used

## Salem 5,138

Mmm, a nice looking exam question.

Show us that you've done a bit of work yourself, and that you might learn something (as opposed to simply dumping your homework, then hoping to copy/pasting the answer).

Eg.
Which would you use in a for loop to increment the loop control variable? `for ( i = 0 ; i < 10 ; /*i++ or ++i here? */ )` Which would you use for copying a block of memory?

## NicAx64 76

if you not confident enough then what you have to do is:

you remove the optmization of you're compiler and diassemble you're
binary program and see , then you'll get more confident.

Just use a olydebug like program or on visual C++ IDE there is a diassembly viewer that was enabled on debug time. Go there and read
the code for more self confident.

## Salem 5,138

IMO, it's better to understand the concept from a language point of view, than knowing what ONE single implementation does in ONE specific test case.

## firstPerson 761

Which one is most likely , ++i or i++
:

``````//++i  OR i++ ?
{
int temp = i;
i = i+1;
return temp;
}``````
``````//++i OR i++ ?
{
i = i + 1;
return i;
}``````

++i is called pre-increment
i++ is called post-increment

## Duoas 1,025

Which is equivalent to `n = n + 1;`

1. `++n;`
2. `n++;`

are meaningless. They are the same.

What is the difference between:

• `x = n++;`
• `x = ++n;`

Once that is understood then you can get into stuff like avoiding object temporaries for non-native types. (See the C++FAQ-Lite.)

Hope this helps.

## manishanibhwani

i need the difference between i++ and ++i, where is i++ used and where ++i is used

++i means increment the value of i by 1 n then use it. "change the value n then use"
i++ means use the value of i as it is and after using increment the value by 1"use and then change"