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

There are several reasons:

  • Not all addresses are created equal; in particular, in non Von Neuman (e.g. Harvard) architectures pointers to code memory (where you often store constants) and a pointers to data memory are different.
  • You need to know the underlying type in order to perform your accesses correctly. For example, reading or writing a char is different from reading or writing a double.
  • You need additional information to perform pointer arithmetic.

Note that there is a pointer type that means “simply a pointer” in C, called void*. You can use this pointer to transfer an address in memory, but you need to cast it to something useful in order to perform operations in the memory pointed to by void*.

Leave a Comment