Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If a pointer's address is 64 bits, why does it appear as 6 bytes when printed?

Tags:

c

pointers

#include <stdio.h>
int main(void){
  int *ptr;
  printf("the value of ptr is %p",ptr);
}

This gives me 0x7fffbd8ce900, which is only 6 bytes. Should it be 8 bytes (64bit)?

like image 936
mko Avatar asked Jul 17 '12 03:07

mko


People also ask

Are memory addresses in bits or bytes?

Each address identifies a single byte (eight bits) of storage.

How long is a 64-bit address?

In 64-bit Windows, the theoretical amount of virtual address space is 2^64 bytes (16 exabytes), but only a small portion of the 16-exabyte range is actually used.

Why is the size of a pointer 8 bytes?

The pointer is 8 bytes, because you are compiling for a 64bit system. The int it is pointing at is 4 bytes.

How many bytes is a pointer?

Note that all pointers are 8 bytes.


1 Answers

Although a pointer is 64 bits, current processors actually only support 48 bits, so the upper two bytes of an address are always either 0000 or (due to sign-extension) FFFF.

In the future, if 48 bits is no longer enough, new processors can add support for 56-bit or 64-bit virtual addresses, and existing programs will be able to utilize the additional space since they're already using 64-bit pointers.

like image 109
Wyzard Avatar answered Oct 15 '22 22:10

Wyzard