Why does that give an error?Code:int *x, y; x = y;
This is a discussion on Pointer/Variable within the C++ Programming forums, part of the General Programming Boards category; Code: int *x, y; x = y; Why does that give an error?...
Why does that give an error?Code:int *x, y; x = y;
That statement declares x as an integer pointer and y as an integer (not a pointer) which are not the same. Perhaps you meant:
...which would declare both x and y as pointers.Code:int *x, *y; ... x = y;
[edit]y should actually point to something valid before you do such an assignment.[/edit]
I used to be an adventurer like you... then I took an arrow to the knee.
This is also a reason to prefer declaring one pointer per statement:
Code:int* x; int* y;
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
This should make it clear.
Code:int *x, y; == int *x; int y; x = &y; --- int *x, *y; x = y; --- int x, y; x = y; --- int* x, y; == int *x, y; == int * x, y;
Last edited by since; 12-01-2009 at 02:22 PM.
Thank you, it's clear now.![]()