What does (char *) x or (void *) z mean?

后端 未结 7 498
别那么骄傲
别那么骄傲 2021-01-22 03:47

I know char *x means a pointer to char, but I\'m confused about what (char*) x means.

相关标签:
7条回答
  • 2021-01-22 04:28

    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.

    0 讨论(0)
提交回复
热议问题