- #1
Werg22
- 1,431
- 1
Isn't a pointer simply a memory address? Then why is the following illegal?
int x = 1;
char *p = &x;
&x should simply evaluate to an address in memory and that should be stored in the content of p. If this was run on a 32-bit architecture, under ASCII formatting, then
*p = 'a';
Will modify the memory unit at address &x and what would happen is that the first 8 bits of x would be modified to the bit character representation of 'a' effectively changing the value of x.
What is wrong with this reasoning?
int x = 1;
char *p = &x;
&x should simply evaluate to an address in memory and that should be stored in the content of p. If this was run on a 32-bit architecture, under ASCII formatting, then
*p = 'a';
Will modify the memory unit at address &x and what would happen is that the first 8 bits of x would be modified to the bit character representation of 'a' effectively changing the value of x.
What is wrong with this reasoning?
Last edited: