Question: As is the case with many students trying to learn c++ I'm a little confused about pointers and in particular pointers to objects.

A simple pointer such as 

```
int *x = new int(5);

```

is easy to understand because x simply stores the address of a word that stores the int 5.

But what if we have something like 

```
 MyClass *x = new MyClass();

```

In this case x can't point to a word containing an instance of MyClass since it could be larger than a word. 

So the question is what does an object pointer actually point to in memory?

Answer: 
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)`.
If you will change one word in this phrase

> 
> x simply stores the address of a word that stores the int 5
> 
> 
> 

then I hope it will be clear

> 
> x simply stores the address of a **memory** that stores the int 5 or MyClass(); 
> 
> 
> 

Operator new uses the value of `sizeof( int )` or `sizeof( MyClass )` to allocate enough memory. For example sizeof( long long ) is usually greater than sizeof of the mashine word.

Moreover even for integer numbers those size is for example is equal to 4 bytes the compiler can allocate actually 16 bytes instead of 4 bytes. It is implementation defined how much memory will be allocated. Take into account that you may overload the new function that allocates memory.

Take into account the following quote from the C++ Standard

> 
> 6 Unless an object is a bit-field or a base class subobject of zero
>  size, the address of that object is the address of the first byte it
>  occupies.
> 
> 
>