+ 1
C++ - These mysteryous pointers
Why doesn't *y++ increment x? #include <iostream> using namespace std; int main() { int x, *y; x = 5; y = &x; *y++; cout << x << endl; x--; cout << x; return 0; }
5 Respostas
+ 3
~ swim ~ yes i realised it, its pointing to another address. Indeed.
+ 3
A pointer is a memory address that contains a value. If you increment a pointer, you go to the next address position. It does not increment the value contained in the pointer
+ 2
Yes, you can do ++*y; or, *y=*y+1; or (*y)++;
Seems that pointers need first increment and then assignment. In second case *y=*y+1; all second part (*y+1) is assigned to *y. In case *y++; i suppose that first *y =*y and then +1 which is lost. I think its like typing *y+1; with no assignment or you just do this *(y+1) which is just another menory address.
And thats why i hate pointers. :D