As far as I know about data types in C/C++, while declaring a variable, we need to declare its data type, which tells the compiler to reserve the number of bytes in the memo
The problem is not about pointer size but pointer dereferencing. (wether in C or C++)
Say you have:
int* someint;
float* somefloat;
*someint
references a memory size of sizeof(int)
, whereas *somefloat
references a memory size of sizeof(float)
which are different.
What size a pointer needs depends on the system you are using. On a x86_64
system the pointer size might by 64 bit.
The reason why you need the data type for pointers is because the compiler has to know what the size of the memory cell is, among others, the pointer is pointing to. Also type safety cannot be ensured w/o the type. Also, you would have to typecast every pointer when accessing structures from the pointer.
You also could use a void
pointer and do everything by hand. But why should you want that?