Pointer/address type casting

后端 未结 5 1646
梦如初夏
梦如初夏 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 14:56

    The problem is that when you're performing the casts (aside from whether or not the kind of casting you're doing is a good idea or not) is that the cast expression results in an rvalue.

    rvalues cannot be assigned to or have their addreses taken.

提交回复
热议问题