Why array assignment operation doesn't exist but structure assignment does in C language?

前端 未结 7 1978
被撕碎了的回忆
被撕碎了的回忆 2021-01-18 01:47
int a[10];
int b[10];

a = b; // illegal

typedef struct {
    int real;
    int imag;
    } complex;

complex c,d;
c = d; //legal

[I realize that

7条回答
  •  深忆病人
    2021-01-18 02:16

    An array name is a const pointer so you can't change what it is pointing to.

    Assuming that you meant c = d on the last line is legal, it's simply copying a non-const variable to another non-const variable, which is perfectly legal.

提交回复
热议问题