Why does that give an error?Code:int *x, y; x = y;
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]
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
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 03:22 PM.
Thank you, it's clear now.