I tried to run this code,
int *p;
float q;
q = 6.6;
p = &q;
Though it will be a warning, but i think &q
and p
In addition to what is said by teppic,
Consider,
int a = 5;
int *p = &a;
In this case we indicate to the compiler that p
is going to point to an integer. So it is known that when we do something like *p
, at runtime, the no. of bytes equal to size of an int
would be read.
If you assign address of a datatype occupying x
number of bytes to a pointer of which is declared to hold the address of datatypes of fewer bytes than x
, you read the wrong number of bytes when using the indirection operator.