This may be simple but it confuses me.
int x;
int *p = NULL;
int *q = &x;
What happens when
q = p; // Address where q points to equals NULL .
&x = q; // I don't think this is possible .
*q = 7; // Value of memory where q is pointing to is 7?
*q = &x // That's just placing the address of x into memory where q points to right?
x = NULL;
q = p;Yes.
qnow points toNULL, just likep.&x = q;Not legal. You cannot reassign the address of a variable.
*q = 7;Yes, sets the memory of the address where q is pointing to 7. If
qpoints toNULLthen this will cause an error.*q = &x;Not legal,This is legal, as there is an implicit cast fromqpoints to an integer, so you cannot assign an address to it.int*(&x) toint(*q), but not very safe. In C++, it is just a plain error. You are right in saying that it places the address ofx(cast to anint) into the memory pointed to byq.