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

 Print  |  
Question:  
Array is an lvalue or not?


Answer:
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;
...


November 11, 2005 01:32:43 #1
    Member Since: Visitor    Total Comments: N/A 

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
     

 

Back To Question