简体   繁体   中英

If pointers are just integers that hold an address (4 bytes - 32 bits), how do they store the extra addresses in 64-bit memory?

When using the sizeof() function in c++ programs, the pointers I've looked at seem to all return a size of 4 bytes. I've seen online that pointers are just integer memory addresses. How does this make sense in 64 bit architectures that would then potentially have memory addresses that cannot be accessed in 4 bytes?

Most modern 64-bit operating systems support a 32-bit mode for backward-compatibility. If sizeof(void*) == 4 with you, then you are probably targetting the 32-bit platform of your operating system, so that your program will run in 32-bit mode.

Check your compiler's documentation on how to target the 64-bit platform of your operating system. Afterwards, you should notice that sizeof(void*) == 8 .

If pointers are just integers that hold an address (4 bytes - 32 bits), how do they store the extra addresses in 64-bit memory?

A 32 bit pointer cannot store 64 bit addresses. This is why pointers are 64 bits on 64 bit systems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM