Why is the data type needed in pointer declarations?

前端 未结 8 667
萌比男神i
萌比男神i 2020-12-04 22:07

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

8条回答
  •  死守一世寂寞
    2020-12-04 22:36

    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.

提交回复
热议问题