0

A pointer on a 32 bit machine has size 4 bytes, whereas on a 64 bit machine it has 8 bytes.

For example,

int i = 1;
ptr2int* int = &i

then

std::cout << "Size of pointer to i is " << sizeof(ptr2int) << std::endl;

gives 4 on a 32 bit machine, but 8 if calculated by a 64 bit processor.

Why is that?

Svalbard
  • 182
  • 2
  • 13
  • 1
    So you've found that a 32bit machine has 32bit pointers and a 64bit machine has 64bit pointers, to be honest there are some other options but this seems to me to be the least surprising option. Maybe you can add something to your question to make it clear what you want to have explained to you? – harold Oct 21 '21 at 21:56
  • @harold I think I actually get it. The address of a 64 bit computer contains 64 "positions" or bits (i.e. zeros or ones), whereas the address of a 32 bit machine contains 32 bits. A pointer saves an address in memory, so a pointer on a 64 bit computer is twice as big as one on a 32 bit computer. – Svalbard Oct 21 '21 at 22:27
  • 1
    Does this answer your question? [How many bytes do pointers take up?](https://stackoverflow.com/questions/20763616/how-many-bytes-do-pointers-take-up) – HTF Oct 22 '21 at 05:29

0 Answers0