Why does that give an error?Code:int *x, y;
x = y;
Printable View
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]
This is also a reason to prefer declaring one pointer per statement:
Code:int* x;
int* y;
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;
Thank you, it's clear now. :)