The value of a pointer represents an address in memory. Each C implementation may decide for itself how the pointer represents an address, but it is common in modern C implementations that the bytes of the address space are effectively numbered with consecutive integers starting from zero, and the bits representing a pointer are that address in binary. In effect, a pointer “value” of 46,912,496,308,240 means the byte number 46,912,496,308,240 in the address space.
Note this does not mean your system has 46,912,496,308,241 bytes of memory; not all of the address space is used. Different parts of the memory of a process (such as initialized data, code, stack, and dynamically allocated memory) are started at different places so they have room to grow without bumping into each other. This leaves gaps where the address space is not mapped to usable memory.
You should not print a pointer by formatting it with %ld
. Correct ways to print a pointer include converting it to void *
and using %p
:
printf("ptr = %p\n", (void *) ptr);
or converting it to uintptr_t
and using "%" PRIxPTR
, after including <inttypes.h>
and <stdint.h>
:
printf("ptr = %" PRIxPTR "\n", (uintptr_t) ptr);