Why are there different types of pointers for different data types in C?

前端 未结 7 1337
难免孤独
难免孤独 2020-12-03 15:08

If we have to hold an address of any data type then we require a pointer of that data type.

But a pointer is simply an address, and an address is always int

7条回答
  •  日久生厌
    2020-12-03 15:36

    It's mostly for those who read the code after you so they could know what is stored at that address. Also, if you do any pointer arithmetics in your code, the compiler needs to know how much is he supposed to move forward if you do something like pSomething++, which is given by the type of the pointer, since the size of your data type is known before compilation.

提交回复
热议问题