Pointers in C
# Pointer size
The size of a pointer is dependent on the machine for which the code is compiled. On 64-bit computers it’s 64 bits. It also can be different from size_t
size, which can hold the size of the largest object.
It’s not guaranteed by the standard that all pointers are the same size. But on practice they are. It’s guaranteed that char *
and void *
are the same size, all struct *
the same size, all union *
, etc.
Casting pointers to unsigned long
to do various things with them can cause undefined behavior! Whether unsigned long
is the same size as a pointer is machine-dependent. Use uintptr_t
instead. ^96aaca
# Syntax
Two pointers:
|
|
One pointer, one int:
|
|
References:
- What is the size of a pointer in C? - Quora
- Are all data pointers the same size in one platform for all data types?
- Printing the Value of a Pointer to an Object
- c++ - What is uintptr_t data type - Stack Overflow