National Day Leisure to see C + +, encounter C language of a problem, feel very interesting.
"Is there a string type variable in the C language?"
The string here has two meanings.
(1) If string is a common word, "C language has character type variables", answer, yes. Character types are declared with char.
Char str[]= "This is a string";
(2) If string is a special term, "C" has a string type variable? A string is a class, is of class, is not a
type, is not a
The C language does not have a string type variable, but does not represent a method that does not manage the string of operations because of its set of C string variables:
Know:
C string Variable String:char string []= "abc"; Equivalent to: char string [4]= "abc";
Why is the array length 4? Because the C language compiler will be at the end of the string to fill the ' "" as an empty worthy flag, it also exclusive one character;
You may have a problem : Does the C language have an array of characters? How to distinguish it from a C string?
This is a great question: Please note: char string1 [3]={' a ', ' B ', ' C '}; There will be no ' ' sign behind this string1, so it's not what we call
C string variable.
C string variable initialization without specifying the length, the C system will automatically judge the complement, which brings great convenience, but there is a limit on the assignment: initialization and assignment can not be separated: char a_string[10];a_string= "Hello" ; it's wrong.
There's always a solution : Use predefined functions to assign values to:include<cstring> strcpy (a_string, "hello"); Unfortunately, this function does not detect problems with string arrays that are out of bounds. You can use strncpy (a_string, "Hello", 9); This function has one more array maximum length parameter.
Other functions in include<cstring>:
1. Judge whether the string is equal strcmp (STR1,STR2);
Note the inverse logic of this function, equality returns FALSE (0), unequal return True (not 0 values);
2.strlen (str); Returns the length of the string;
3.strcat (STR1,STR2); str2 product received str1;
In addition, there is no bool type in C language, but it can be replaced by int and char entirely.
0 corresponding c++f false, not 0 value true