What if there is no string type variable in the C language? What if I don't have bool? __c language

Source: Internet
Author: User
Tags array length
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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.