C++ problem

Björn Lindberg d95-bli at nada.kth.se
Fri Aug 6 03:55:01 PDT 2004

(Sorry, I forgot to answer your actual question! :-)

michael <michael8110 at terra.com.br> writes:

int main()
    char a[20]="citroen";  (*)
    car c;
    c.itsName=a;  //line 10
    return 0;

> Would someone be so kind as to shed some light on this confusing state
> of  affairs?I mean,if it's ok to assign "citroen" to a[20] ,why not
> then also  to c.itsName[20] ?Thank you!

The answer is that you are not allowed to assign "citroen" to a[20]
either. The line at (*), despite the equal sign, is not an assignment,
it is an /initialization/. Try to separate the line in two and you
will see that you get the same error:

    char a[20];
    a = "citroen"; // ERROR

The distinction between initialization and assignment is crucial, but
can be difficult in languages such as C++, since the syntax is so


More information about the lfs-chat mailing list