I got confused in interpreting this line:
a = (char*) b;
while a
and b
are both declared to be of type char*
.
Can anyone explain it to me please?
I got confused in interpreting this line:
a = (char*) b;
while a
and b
are both declared to be of type char*
.
Can anyone explain it to me please?
If they are of the same type, there is no need to use casting in the expression and it is the same as
a = b;
Edit: example casting with pointers
If you are using a C++ compiler, you need casting when calling malloc function otherwise you get an error message. This function returns a void*
pointer and you need to explicitly cast it to its destination type as implicit conversion from void*
has not been inherited from C.