I know char *x
means a pointer to char, but I\'m confused about what (char*) x
means.
The expression (char *)x
is a type cast which returns the value of x
converted to type char *
.
The results of a cast can be very different depending on the operand and target types: For example, you can use casts to round floating-point values to integer precision, get rid of qualifiers like const
, convert a pointer to integer for advanced address calculations like alignment checks and many other things.
However, not all possible casts result in legal values - eg, casting pointers can violate aliasing and alignment rules.
Converting a (valid) non-function pointer to char *
is always legal and useful when doing byte-based pointer arithmetics.