Why can’t I assign an array variable directly to another array variable with the ‘=’ operator?

Because when you have a function call like this UCSDStudent( char name[] ) only the adress of the array name is copied instead of the whole array. It is a C\C++ feature.

Furthermore the name defined as char name [20] is not a modifiable lvalue.

Regarding strcpy: it will bring undefined behaivour as if your source array doesn’t have a NULL character it will copy some trash to this->name too. You may read more about strcpy here

Leave a Comment