c language character constants can not be assigned to an array of characters


This is an error, the reason that they can not use assignment; char s [20]; s = "helo" string constant directly assigned to a character array.
S char [20 is];
char SS [] = "Hello";
S = SS; this is wrong because the assignment statement can not be used directly to an array of characters assigned to a character array

that is copied (c language string, but in c ++ string class, the above assignment is correct) must strcpy () function to achieve.

The char a [] = "toyou" ; as above is correct? ? ? That is because when we declare an array variable is that its open space, and their initialization, this is consistent with c language syntax. The above is not grammatical.

char s [] = "hello"; assignment mode of this string is no problem. To understand this assignment way, we must first understand the double quotation marks (Special Note: This is a double quotation mark, when not assigned to a broke single quotes) what has been done in this statement. Double quotes mainly do three work are:

(1) the application space (the constant region), the stored string.

(2) adding the end of the string "\ 0."

(3) return address.

The return address here on assignment to the type char * pointer variable p.

We can define an array first, and then to fill in something to this array by scanf function. This is not illnesses , code Appendix below.

Guess you like

Origin www.cnblogs.com/littleswan/p/12162958.html