Yesterday I was in class, and at some point the instructor was talking about C code. He said:
What is the purpose of making a pointer cast in C? The only
What your instructor said about all pointer types sharing the same representation is generally true for real-life implementations of C language.
However, it is not true from the point of view of abstract C language itself. C language guarantees that
char * pointers are represented in the same way as void * pointers.T (const, volatile, restrict) are represented in the same way as pointers to unqualified T.That is all. No other guarantees exist. Which means that as far as the language itself is concerned, int * pointer has different representation from double * pointer. And pointer to struct S is represented differently from pointer to union U.
However, your example with char_pointer and int_pointer, as presented, is not exactly illustrative. The char_pointer = int_pointer; assignment is simply invalid (as in "does not compile"). Language does not support implicit conversions between incompatible pointer types. Such conversions always require an explicit cast operator.