# Thread: What does ++ mean?

1. ## What does ++ mean?

I trying to understand the code statements below, but I'm unsure as to what the ++ means.
Code:
```float x = *w++;
*z++ = y;```
Does the variable x hold the value that is next to the value pointed to by *w? Does it following then that the value next to the value pointed to by *z is equal to y?

2. the ++ increases the variables value by 1. It is just like var = var+1; just made short

3. c++
c = c + 1

4. c += 1

5. w and z are (probably) pointers in that code. The ++ means that they point to the next object in memory. It is a mechanism for going through an array.

*w++ and *++w are different, even though both move the pointer value. The first returns the original pointer value, and when the statement has completed the pointer is incremented. That means in your example above that x gets the value w was pointing to before the ++ part. If it had been float x = *++w;, then w would have been incremented first, and then x would have gotten the value pointed to by w after the increment.

Same goes for the second part. Because it is *z++, the value originally pointed to by z gets updated to y, and then the z pointer is incremented to the next element in the array.

6. Does the variable x hold the value that is next to the value pointed to by *w?
It could depending on the precedence rules, i.e. which of the operator * or ++ gets applied first. Looking at an operator precedence table, ++ has a higher precedence. Since apparently 'w' is a pointer, ++ will move the pointer to the next element.

7. Operator precedence doesn't matter in determining whether the value x is set to is the originally pointed to value or the value pointed to after the increment. It only determines whether the pointer is incremented or the value pointed to is incremented. Since ++ has precedence, the pointer is incremented.

What matters as to what value x gets is whether it is prefix or postfix. In this case it is postfix, so x gets the originally pointed to value, and the pointer is incremeneted afterwards.

8. c++ adds 1 to c

c =+ 1 means c= c + 1

9. I was going to reply that. But I decided to test, because I'm a little unclear on the subject in reference to pointers. I really need to read a reference.

Anyway, I'm not sure how its happening. But it appears *z++ will change y to point to the next (or previous, can't tell) value in memory, and then you would be assigning the value pointed to by z to w. The thing is that the assignment doesn't carry through when its in one statement for some reason. However if you split the statement up it will work. Which is almost exactly what the OP asked if it was doing.

Pointers just became fun.

Code:
```#include <iostream>

int main()
{
float a = 10.0;
float b = 5.0;
float c = 2.5;

float* y = &c;

std::cout << *y << std::endl; //Output: 2.5

*y--; //no longer points to c, and now points to undefined
std::cout << *y << std::endl; //Output: something x10^-39

*y++; //no longer points to undefined, and now points back to c
std::cout << *y << std::endl; //Output: 2.5

*y++; //no longer points to c, and now points to b
std::cout << *y << std::endl; //Output: 5.0

*y++; //no longer points to b, and now points to a
std::cout << *y << std::endl; //Output: 10.0

++*y; //increments the value of pointed to by the pointer
std::cout << *y << std::endl; //Output: 11.0

++*y; //increments the value of pointed to by the pointer
std::cout << *y << std::endl; //Output: 12.0

--*y; //decrements the value of pointed to by the pointer
std::cout << *y << std::endl; //Output: 11.0

*y--; //no longer points to a, and now points to b
*y = c; //change the value pointed to by the pointer (b) to c
std::cout << b << std::endl; //Output: 2.5

*y++ = a; //no longer points to b, and now points back to a, and attempt to change the value pointed to by the pointer (b) to c
std::cout << b << std::endl; //Output: 5.0 (should output 2.5 because its being assigned c's value, but outputs a's value of 11.0)

std::cin.get();
}```
Edit: Looks like 7stud and Daved explained it. But still, code to match here.

Edit: I understand now. I forgot. The reason *y++ = a; doesn't work is because it increments the pointer to the next place after the assignment.

10. Originally Posted by rodrigorules

c =+ 1 means c= c + 1
well thats the same, but i think it shouldn't be =+, it should +=;
And what does
++c;
means?
I know it's possible.

11. Originally Posted by ElastoManiac
well thats the same, but i think it shouldn't be =+, it should +=;
And what does
++c;
means?
I know it's possible.
It meants c is incremented before it returns its value.

int c = 5, a = 0;

a = ++c; //would be 6
a = c++; //would be 5

12. Dae, you shouldn't be using ++ or -- on y in your example anywhere. It's all undefined. It worked in some cases for you because of the way memory is laid out on your current platform.

Try making an array and then point y at the array. Then you can see a better (and more legal) version of what's going on.

13. and just to make this thread even more confusing (*x)++ will incremenet the value pointer to by x rather than x pointer itself.

14. Originally Posted by Ancient Dragon
and just to make this thread even more confusing (*x)++ will incremenet the value pointer to by x rather than x pointer itself.
interesting

15. Originally Posted by ElastoManiac
well thats the same, but i think it shouldn't be =+, it should +=;
And what does
++c;
means?
I know it's possible.
think of it like this
var++
is equivalent to the following function
Code:
```int Postfix(int& var)
{
int temp = var;
var = var + 1;
return temp;
}```
whereas
++var
is equivalent to the following function
Code:
```int Prefix(int& var)
{
var = var + 1;
return var;
}```