Pointer/address type casting

后端 未结 5 1647
梦如初夏
梦如初夏 2021-02-02 14:50

I have the following variables:

char *p;
int l=65;

Why do the following casts fail?

(int *)p=&l;

and:

5条回答
  •  借酒劲吻你
    2021-02-02 15:19

    In plain C, which is not that strict to type conversions, this code would compile and actually work. On a C++ compiler it would actually require explicit casts as already mentioned (see other answers).

提交回复
热议问题