I thought that pointers took up less memory, and were more efficient but when I use sizeof() on a pointer, it says it uses twice the memory as an integer. What am I missing here? Here's my code
int p = 1;
Int a = 1;
cout << sizeof(pointera) << endl;
cout << sizeof(a) << endl;
pointer contains a memory address. When you call the sizeof on a pointer it gives the size of the address. In a 64 bit computer a memory address would be 8 bytes.
Int *pointera = &p; sizeof(pointera);
Here pointera stores the memory address of p. This address is 64 bit which means 8 bytes.
size of int, double and char are different but if you calculate the size of pointer of these data types than they would all be of same size in the same computer.