The size of a structure's allocation is not that simple, there's the issue of alignment . Depending on the compiler, the directives, the code, and the platform you're running on may be different but there's a reasonable chance that it's 8 bytes anyway, just do not count this as being right. This can be found by code .
#include <iostream>
using namespace std;
struct Exemplo { int x; int b; };
int main() {
Exemplo exemplo;
cout << "Tamanho de exemplo: " << sizeof(exemplo) << endl;
cout << "Valor de exemplo.x: " << exemplo.x << endl;
cout << "Valor de exemplo.b: " << exemplo.b << endl;
Exemplo *exemplo2 = new Exemplo;
cout << "Tamanho de exemplo2: " << sizeof(exemplo2) << endl;
cout << "Tamanho do objeto apontado por exemplo2: " << sizeof(*exemplo2) << endl;
cout << "Valor de exemplo2 (o ponteiro): " << exemplo2 << endl;
cout << "Valor de exemplo2->x: " << exemplo2->x << endl;
cout << "Valor de exemplo2->b: " << exemplo2->b << endl;
cout << "Tamanho de exemplo2.x: " << sizeof(exemplo2->x) << endl;
return 0;
}
Dynamic allocation allocates the memory required for the object you want to allocate. It does not matter if it is in the stack or heap , the size should be the same. In case it will allocate space for an object, in its example it would have 8 bytes and the variable will receive the pointer for this object. The pointer size is fixed to the application, all pointers have the same size, which varies is the size of the object it points to. Pointer and the object he points out are distinct things that have an eventual relationship. In case the object that would be pointed out should have 8 bytes , after all it would be the same structure.
In a simple example the object would be in the heap and the pointer allocated in the variable would be in stack . But nothing prevents the pointer from being heap also just the code you prefer to put there for some reason.
If you want to understand more about pointer, you have a question on the subject here on the site.