指针左值错误
Posted idyllcheung
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了指针左值错误相关的知识,希望对你有一定的参考价值。
1
2 int main(void)
3 {
4 int a=1;
5 char *pp;
6 void *p=&a;
7 p++;
8 p+=a;
9 pp=(char *)p;
10 pp+=a;
11 //(char *)p +=a;
12 }
(char *)p +=a; 会报左值错误
The result of (int *) p
is a value. This is different from an lvalue. An lvalue (potentially) designates an object. For example, after int x = 3;
, the name x
designates the object that we defined. We can use it in an expression generally, such as y = 2*x
, and then the x
is used for its value. But we can also use it in an assignment, such as x = 5
, and then the x
is used for the object.
以上是关于指针左值错误的主要内容,如果未能解决你的问题,请参考以下文章