-2

An lvalue is defined as an expression to which a value can be assigned. And it is illegal to assign and array with a array value. E.g.:

int x[2],y[2];
x = y;

Whereas structures can be treated as lvalues. Below structure assignment is valid.

typedef struct car {
    char color[20];
    int price;
} CAR;

CAR audi, bmw;
audi = bmw;

What is the difference?

Mirakurun
  • 4,859
  • 5
  • 16
  • 32
Jagan
  • 159
  • 3
  • 11

1 Answers1

3

There are historic reasons why arrays are not assignable on themselves, but are assignable inside structs. There is really no technical reason for this discrepancy.

Anecdottal heresay is that when C was designed, it was based on a certain language (don't remember which one!) which didn't have array assingment, so this feature was exluded from C as well - to preserve compatibility. However, this language didn't have structs, so array assingment inside structs was OKayed.

SergeyA
  • 61,605
  • 5
  • 78
  • 137