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

后端 未结 7 506
别那么骄傲
别那么骄傲 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:27

    It's a cast. You are instructing the compiler to treat x as if it were a char *, regardless of its real type. Casts should only be used if you really know what you are doing.

    For some built-in types, the compiler may perform a meaningful conversion, e.g. converting a double to an int by rounding, but for other types you may not get what you expect.

提交回复
热议问题