|
|
|
|||
‘x’
is a name of array and not an lvalue. So it cannot be used on the
left hand side in an assignment statement. Consider the following statements int
x[6]; int
n; x[0]
= 5; x[1] = 2; x = 3; //not allowed x = a + b; // not allowed x = &n; // not allowed In the above code snippet, we have
declared an array x of int. Now we can assign values to the
elements of x as x[0] = 5 or x[1] = 2 and so on. The last three statements are not allowed.
What does the statement x = 3;
mean? As x is a name of array and
this statement is not clear, what we are trying to do here? Are we trying to
assign 3 to each element of the array? This statement is not clear.
Resultantly, it can not be allowed. The statement x = a + b is also not allowed. There is nothing wrong with a + b. But we cannot assign the sum of
values of a and b to x. In the statement x =
&n, we are trying to assign the memory address of n to x which is not allowed. The reason is the name x is not lvalue and we cannot assign any value to it. For understanding
purposes, consider x as a constant.
Its name or memory location can not be changed. This is a collective name for
six locations. We can access these locations as x[0], x[1] up to x[5].
This is the way arrays are manipulated. |
|||||
|
BACK |
HOME |
NEXT |
||