指针左值错误

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.

 

以上是关于指针左值错误的主要内容,如果未能解决你的问题,请参考以下文章

指针左值错误

指向函数指针的指针 - 表达式必须是可修改的左值

C:试图将指针值复制到另一个指针中,得到可修改的左值错误

取消引用的指针是有效的左值吗?

表达式必须是结构指针上的可修改左值

唯一指针:左值引用与右值引用函数调用