-->

What does “lvalue required” mean in a C compiler e

2020-04-30 03:21发布

问题:

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 7 years ago.
 #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.