0

should the size of int*, double* be the same? (4 or 8?) as the int* just means the data type the pointer points while we are saving the address of a.

int a; double b;

int is 4 bytes while double is 8 bytes.

int* pa = &a; double* pb = &b;

int* and double* same bytes?

1 Answer 1

1

A pointer contains an address of whatever it points at, nothing more, nothing less. The size depends on the size of an address for the architecture that it runs on. In a 64-bit architecture, it will be 8 bytes (8 bytes * 8 bits per byte = 64 bits), and in a 32 bit architecture, it would be 4 bytes. The size of the object pointed at has no bearing on the size of the pointer.

However, the pointer type does have a bearing on how the pointer will be treated. As long as you malloc the correct size memory to the pointer, it will treat that pointer as the address of that type of object.

Think of a pointer this way. My finger can point at a house, or a car, or a golf ball, but the size of my finger doesn't change. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .