GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 4 of 433    Print  
Array is an lvalue or not?
An lvalue was defined as an expression to which a value can be assigned. Is an array an expression
to which we can assign a value? The answer to this question is no, because an array is composed of several separate array elements that cannot be treated as a whole for assignment purposes.
The following statement is therefore illegal:
int x[5], y[5];
x = y;
Additionally, you might want to copy the whole array all at once. You can do so using a library function such as the memcpy() function, which is shown here:
memcpy(x, y, sizeof(y));
 
It should be noted here that unlike arrays, structures can be treated as lvalues. Thus, you can assign one
structure variable to another structure variable of the same type, such as this:
typedef struct t_name
{
char last_name[25];
char first_name[15];
char middle_init[2];
} NAME;
...
NAME my_name, your_name;
...
your_name = my_name;
...



  
Total Answers and Comments: 3 Last Update: December 24, 2007   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 28, 2005 01:32:43   #1  
       

RE: Array is an lvalue or not?
Basically lvalue is a storage location where data can be stored/ assigned and moreover it is not an expression. rvalue is an expresion which has a value. all lvalues can be used as rvalues. But all rvalues can't be used as lvalues. int a[100];a is always an rvalue, but a[i] can be lvalue as well as rvalue
 
Is this answer useful? Yes | No
August 30, 2006 06:13:16   #2  
Deepak kumar Prasad        

RE: Array is an lvalue or not?

The rvalue is the data value of the variable, that is, what information it contains. The "r" in rvalue can be thought of as "read" value. A variable also has an associated lvalue. The "l" in lvalue can be though of as location, meaning that a variable has a location that data or information can be put into. This is contrasted with a constant. A constant has some data value, that is an rvalue. But, it cannot be written to. It does not have an lvalue.


 
Is this answer useful? Yes | No
December 24, 2007 20:29:57   #3  
i_spy Member Since: December 2007   Contribution: 2    

RE: Array is an lvalue or not?
I have a doubt. How about this statement:

int a[] = {"1", "4", "6", "3"};

It is definition and initialization but is also assignment for whole of array a.
Isn's array a being treated here as an lvalue?

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape