In the case of objects, just like an array, it points to the first element contained within the data structure. Pointers can only point to one address in memory. They do not store any more information than this value. What makes them look like you can point to larger types is just the compiler at work. Actually, it stands even for ints which takes 4 bytes in memory. An int pointer will only point to the first byte of said data structure and the compiler will take care of loading the right amount of memory when needed based on the result of the sizeof(T)
operator.
For instance, sizeof(int)
returns 4 which is the amount of bytes in memory required to store the entire value of an int. If you create a pointer to an int, it will refer to the first of those 4 bytes using a 32 or 64 bit-long address depending on your target processor asuming an x86 architecture. If an object MyClass contains 3 ints and 1 double, the sizeof(MyClass)
operator will return 20 (3 * 4 + 8)
. Again, a pointer to MyClass will only point to the first byte using a 32 or 64 bit address.
The size of pointers stays the same across an entire CPU architecture. If your CPU can allocate 8 bits of memory, your pointers will be a single byte long. In other words, sizeof(T*) == sizeof(unsigned char)
. On an x86_64 target architecture, the size of a pointer will 64 bit in length thus sizeof(T*) == sizeof(long long)
.