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

前端 未结 7 1305
难免孤独
难免孤独 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:30

    Pointers are not just int. They implicitly have semantics.

    Here are a couple of examples:

    • p->member only makes sense if you know what type p points to.

    • p = p+1; behaves differently depending on the size of the object you point to (in the sense that 'p' in in fact incremented, when seen as an unsigned integer, by the size of the type it points to).

提交回复
热议问题