++?

What does "++" mean? I have seen it used in the responses to some of my questions, and some questions by other people. I know that to manually debug a program, I did this:

1
2
3
4
5
6
7
8
9
int blah()
{
int v=0;
v++;
//stuff....
cout<<"In blah";
cout<<v;
//more stuff....
}


This displayed "In blah" then it displayed how many times the function had been called. I know that however many times the function is called, it adds to the outputted number. Same thing with while loops. However many times it loops, that's how many is outputted.
This is the only way I know how to use "++." I would love to know all the ways to use it.

Thanks!
Last edited on
v++ adds one to v, but returns the original v.
++v adds one to v and returns the modified v.
Cool! I've also seen, in code, int something(int x=5; int s=4; x++). What does this mean?
That is a for loop. Do you mean?
1
2
3
4
for( x=5; s ==4; x++)
{
     //any statement here
}

The initial value of the integer x is 5. As long as the integer s is equal to 4, the value of x will increase by one.
Last edited on
v++ is basically a shorthand way of doing v = v + 1. there is also v += 2, which is equal to v = v + 2, which is again a shorthand way of doing it.
Excellent!
can v=v+2 written as v=+2?

v++ adds one to v, but returns the original v.

means v=v+1, so the v+ 1 will overwrite v??

eg. 9=9+1
so 10=9+1

like that?? what im understand is...the number have been overwrite is displayed

++v adds one to v and returns the modified v.

but for this, in the source code, the number is add by 1 but it still display the number that has NOT add yet right??





v++ isn't neccesarily identical to +=1, but it does mean increase by one, for complex types that can be something else. For example, you iterate an iterator using the ++ operator (+=1 wouldn't work).
richgirl wrote:
can v=v+2 written as v=+2?
No. writing this v=+2 the + is an unary operator which is actually v=2.

1
2
3
int v = 0;
int x = v++; // x = 0 / v = 1
int y = ++v; // y = 2 / v = 2 
Topic archived. No new replies allowed.