We have
int i;
which have 4 bytes lets have address from 1000 to 1004. if we declared a pointer
int* p;
p = &i;
now is the pointer holds only 1000 or from 1000 to 1004?
The pointer holds the addresses then why we need to declare a datatype to a variable?
when we declare a datatype to pointer, can a pointer can be typecasted?
why can't we use void* p
which can hold any datatype?
int
extends to 1003 is implied by the declaration of the pointer as being ofint*
type. You can use avoid*
, but then you lose information about the underlying type and its size. Sometimes recasting pointers or overlapping them, can be used to perform all sorts of efficient tricks, but those tricks are out of vogue nowadays. – Steve Feb 8 '18 at 14:40