LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-21-2012, 11:33 PM   #1
tushar_pandey
Member
 
Registered: Jun 2012
Location: ghaziabad , delhi , india
Posts: 105

Rep: Reputation: Disabled
lvalue & rvalue


why and when we face these types of errors !
 
Old 08-21-2012, 11:41 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
They aren't errors. Quote the exact error message you got from the compiler.
 
Old 08-22-2012, 12:16 AM   #3
piyush.sharma
Member
 
Registered: Jul 2012
Location: Delhi, India
Distribution: CentOS
Posts: 82

Rep: Reputation: Disabled
Quote:
Originally Posted by tushar_pandey View Post
why and when we face these types of errors !
"lvalue is required", this message is shown when you don't have a variable on the lift side of assignment. means we have a value but don;t have a space to store it.
try ++x++, it will display because after post increment, pre will be applied on incremented value of x. that will cause your message.
 
Old 08-23-2012, 02:50 AM   #4
kedarp
Member
 
Registered: Jul 2012
Distribution: Ubuntu
Posts: 198
Blog Entries: 3

Rep: Reputation: 23
You will encounter these when you especially work with pointers.
For e.g.

Code:
main()
{
   int a[10];
   
   //now if I try to change the address of the array a
   a++;
   
   //I will get that lvalue required because you are changing the base address of the array.
}
Or you could do this -
Code:
main()
{
   int a[10];
   int *b;
   b=a;         //assign the address of a to b;
   for(int i=0;i<a;i++)
      printf("%d ",*b++);    //and use b to access elements
}

Last edited by kedarp; 08-23-2012 at 04:34 AM.
 
Old 08-23-2012, 08:46 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
It's a computer-science jargon: an lvalue is something that can legitimately appear on the left side of an assignment statement; rvalue on the right.
 
Old 08-23-2012, 09:00 AM   #6
kedarp
Member
 
Registered: Jul 2012
Distribution: Ubuntu
Posts: 198
Blog Entries: 3

Rep: Reputation: 23
In my previous post, a++ actually is a=a+1.
lvalue required is that you cannot assign a new value to a on LHS.
You have to take another variable, i.e. a pointer to 'a'
Code:
int *b;
b=a;
//a=a+1      //lvalue required
b++;         //will work
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++: What EXACTLY comprises a LValue? Aquarius_Girl Programming 21 12-27-2011 10:28 AM
invalid lvalue in assignment cdw9997 Programming 9 05-05-2009 06:16 PM
error: invalid lvalue in assignment nasim751 Programming 3 04-10-2008 01:59 PM
Error: invalid lvalue in assignment xxrsc Linux - Software 1 08-17-2006 01:43 PM
wait_event_interruptible - invalid lvalue in unary `&' 7.e.Q Programming 4 11-08-2004 02:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration