What is "++ and +=" ?

Hello I am a brand new programmer just starting to learn C++. Iv been following a book but iv hit a bit of a snag. The book gave me this example code for a loop:

int main()
{
int i(1), sum(0);
const int max(10);

loop:
sum += i;
if (++i <= max)
goto loop;

cout << endl
<< "sum = " << sum << endl
<< "i = " << i << endl;
return 0;
}

It works but the book does not explain what ++ or += does. The rest of the examples all use ++, --, and += as well so im at a bit of a roadblock here.

Could someone please explain how ++ and += work?
Last edited on
sum += i; is the same as sum = sum + i;

++i is basically incrementing i before executing the statement.
For example:

1
2
3
i = 0;
std::cout<<++i;//outputs 1
//i is 1 here 


Whereas
1
2
3
i = 0;
std::cout<<i++;//outputs 0
//i is 1 here 


Also...that loop is really bad, it uses gotos for no reason when a for loop would be much simpler.
Thanks that really helps me out.
Topic archived. No new replies allowed.