Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - There are too many initialization errors in C++ programs.
There are too many initialization errors in C++ programs.
The problem is that every character should be in single quotation marks. A character refers to a symbol, such as "1", "@" and "=". And the string is a multi-character string, such as "1@=". You need to use single quotation marks when defining characters and double quotation marks when defining strings.

The first character in a single quotation mark actually represents an integer, and the integer value corresponds to the sequence value of the character in the character set adopted by the compiler. Therefore, for compilers using ASCII character sets, the meaning of' a' is exactly the same as that of decimal 97.

The string in double quotation marks indicates a pointer to the starting character of an unknown array, which is initialized by the character between double quotation marks and an extra binary 0 character "\0".

Extended data

When defining a "character", the delimiter should be written in single quotation marks. When printing characters on the screen, you need to use the placeholder "%c" in the printf function. The placeholder "%s" is used in the printf function when printing a string on the screen. It is different from the placeholder "%c" for "Character".

Character "takes up one byte, while" string "takes up multiple bytes. Moreover, at the end of the "string", the character' \0' is automatically added by the compiler. In ASCII code,' \0' represents an empty character.

If you use single quotation marks when defining string constants, the program will report an error. When defining a string, you need to add parentheses after the variable name, which is similar to the format when defining an array.