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

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

    Actually, char *x is a declaration. x is pointer to char.

    If you already have a variable, such as x, you can cast it to a different type. In your case, (char*) x is redundant, since x already is a pointer to char. But you can cast it to int * or something else. Although, note, it's not safe, since an int is larger than a char.

提交回复
热议问题