C语言 C 编译器错误中的“需要左值”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13524104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does "lvalue required" mean in a C compiler error?
提问by ajava
#include<stdio.h> //line 1
#include<conio.h> //line 2
void main() //line 3
{ //line 4
int a=6,g=7,b=3; //line 5
clrscr(); //line 6
printf("%d",a>?g=a:g=b); //line 7
getch(); //line 8
}
Case 1: before saving the file
案例1:在保存文件之前
This will give an error at line no 7 'Lvalue required'. But when I compile no error will come and after running, it produced output 3.
这将在第 7 行“需要左值”处给出错误。但是当我编译时不会出现错误并且运行后,它产生了输出 3。
Case 2 : after saving the file
案例2:保存文件后
And when we save this file then we get an error "Lvalue required'.
当我们保存这个文件时,我们会收到一个错误“需要左值”。
sorry for my mistake and Write question here
抱歉我的错误并在这里写问题
#include<stdio.h> //line 1
#include<conio.h> //line 2
void main() //line 3
{ //line 4
int a=6,g=7,b=3; //line 5
clrscr(); //line 6
printf("%d",a>b?g=a:g=b); //line 7**
getch(); //line 8
}
Case 1: before saving the file
案例1:在保存文件之前
This will give an error at line no 7 'Lvalue required'. But when I compile no error will come and after running, it produced output 3.
这将在第 7 行“需要左值”处给出错误。但是当我编译时不会出现错误并且运行后,它产生了输出 3。
Case 2 : after saving the file
案例2:保存文件后
And when we save this file then we get an error "Lvalue required'.
当我们保存这个文件时,我们会收到一个错误“需要左值”。
回答by lenik
"Lvalue required" means you cannot assign a value to something that has no place in memory. Basically you need a variable to be able to assign a value.
“需要左值”意味着你不能为内存中没有位置的东西赋值。基本上你需要一个变量才能赋值。
in your particular case I would remove a>g=a:g=band replace it with something more comprehensible, because in the current state nobody (including you and your compiler) has any slightest idea what that's supposed to be.
在你的特殊情况下,我会删除a>g=a:g=b它并用更容易理解的东西替换它,因为在当前状态下,没有人(包括你和你的编译器)对它应该是什么有任何想法。
回答by bigfetz
this : printf("%d",a>g=a:g=b); makes no sense. I cant tell if you tying to make a conditional in it which you shouldn't ever do especially for something so simple.
这: printf("%d",a>g=a:g=b); 没有意义。我不知道你是否想要在其中设置一个你不应该做的条件,特别是对于这么简单的事情。
You should read into how printf works becuase either your not understanding what is need which is something like this:
您应该阅读 printf 的工作原理,因为您不了解需要什么,就像这样:
int a = 1;
printf("%d",a);
or you meant to use somthing else but I have never seen a syntax like your doing before here a>g=a:g=b.
或者你打算使用其他东西,但我从来没有见过像你之前在这里做的语法 a>g=a:g=b。

