I cannot understand why are pointer type casts necessary, as long as pointers point to an address and their type is important only when it comes to pointer arithmetic.
That is to say, if I encounter the next code snippet:
int a = 5;
then both
char*b = (char*)&a;
and int*c = (int*)&a
point to the very same memory location.
Indeed, when executing char*b = (char*)&a
part of the memory contents may be lost, but this is due to the type of b
is char*
which can store only sizeof(char)
bytes of memory, and this could be done implicitly.