What does “lvalue required” mean in a C compiler error? [closed]

时光怂恿深爱的人放手 提交于 2019-12-31 04:01:09

问题


 #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

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.

Case 2 : after saving the file

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

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.

Case 2 : after saving the file

And when we save this file then we get an error "Lvalue required'.


回答1:


"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=b and 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.




回答2:


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.

You should read into how printf works becuase either your not understanding what is need which is something like this:

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.



来源:https://stackoverflow.com/questions/13524104/what-does-lvalue-required-mean-in-a-c-compiler-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!