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
Casting a pointer doesn't change the pointer value, it only tells the compiler what to do with the pointer. The pointer itself is just a number, and it doesn't have a type. It's the variable where the pointer is stored that has the type.
There is no difference between your two ways of assigning the pointer (if the compiler lets you do the assigment). Whatever the type of the source pointer variable, the pointer will be used according to the type of the destination variable after the assignment.
You simply can't store an int pointer in a char pointer variable. Once the value is stored in the variable, it has no notion of having been a pointer to an int.
Casting pointers matters when you use the value directly, for example:
int* int_pointer;
int_pointer = malloc(sizeof(int));
*int_pointer = 4;
char c;
c = *(char*)int_pointer;
Casting the pointer means that dereferencing it reads a char from the location, not an int.