The first chapter is the basis of programming. This article is 1.8.2 string constants.
> > > >1.8.2 Â String constant
The real value of characters is that you can string them together to form a sequence of characters, a string constant, or string. A string constant is a contiguous string surrounded by a pair of double quotation marks """, with a null character NUL (null character, NUL is represented as '\0', ASCII code value is 0x00), and its length is a character. The length of the string is increased by 1. Since null strings are used to end strings, both printf() and strcpy() use this as the default precondition.
Note that NULL and NUL are different. NULL means a special pointer, usually defined as ((void *)0), and NUL is a char, defined as \0, which cannot be mixed. Although a character constant is a sequence of characters caused by single quotes, usually consisting of one character, but can also contain multiple characters, such as escape characters, in C their type is int:
Printf("%d", sizeof(char));
Printf("%d", sizeof('a'));
Executing the above code shows that the length of the char is 1, and the length of the character constant is 4.
As long as you use a string in your program, you must determine how to declare the variable that holds the string. If you declare it as an array, you have reserved memory for each character at compile time; if you declare it as a pointer, you don't allocate any memory for the characters at compile time, only allocate space at runtime. such as:
Char cStr[4] = "OK!";
Char *pcStr = "OK!";
The difference between the two is that the array name cStr is a constant, and the pointer name pcStr is a variable. Note that if you use the pointer before initializing the pointer, it may cause a running error if you have the following definition:
Char *pcStr;
Printf("%s", *pcStr);
Since pcStr is not initialized here, the memory it points to is unknown, and strange characters will be printed, so pcStr naturally becomes a wild pointer.
> > > 1. Reference to a string
Since "OK!" is a string constant, it is not modifiable. If you try to do the following:
pcStr[2] = 'Z';
Although the compile time can pass, there will be an error at runtime. If you assign a value like this:
Char cStr[4];
cStr = "OK!";
It is illegal because the array variable name cStr is an unmodifiable constant pointer.
If '\0'' is not stored in the character array, it is just the character constants 'O', 'K', '!', not a string. which is:
Char cStr[] = { 'O', 'K', '!'};
And "char cStr[] = "OK!";" is just another way of writing "char cStr[] = {'O', 'K', '!', '\0'};" A string is a special type of character array variable, so it is stored in the same way as an array variable. The cStr is the array variable name, which represents the address of the 0th element of the array (ie &cStr[0]), cStr+1 represents the address of the first element of the array (ie &cStr[1]), and cStr+2 represents the array variable. The address of the second element (ie &cStr[2]), cStr+3 represents the address of the third element of the array variable (ie &cStr[3]), and its storage form is shown in Figure 1.13.
Figure 1.13 "OK!" storage form
Strings in C language are processed in the form of character array variables. They have attributes of arrays, so they cannot be assigned to the entire character array variable. Characters can only be assigned to character array variables one by one. such as:
Char cStr[4];
cStr[0] = 'O'; cStr[1] = 'K'; cStr[2] = '!'; cStr[3] = '\0';
It stores not the characters themselves, but the character constants (ie stored values) stored in ASCII code.
IdiotSince the string constant ends with '\0' (ASCII code value is 0x00), you can use cStr[i] as the "conditional part (boolean expression)" of the for loop statement to check if cStr[i] is '\0 '(cStr[i] is represented by *(cStr+i)). The idiom used to process each character in a string is as follows:
For(i = 0; cStr[i] != '\0'; i++) ...
It is equivalent to
For(i = 0; cStr[i]; i++) ...
Similarly, "while(cStr[i] != '\0')" is equivalent to "while(cStr[i])".
Of course, you can also use the %s format declarator of the scanf() function to enter a string, as shown in Listing 1.37.
Program Listing 1.37 String Input and Output Sample Program
1 #include
2 int main(int argc, char *argv[])
3 {
4 char cStr[10];
5
6 scanf("%s", cStr);
7 printf("%s", cStr);
8 return 0
9 }
Since cStr represents the starting address of the character array, there is no need to add the & operator before cStr. However, there is a potential danger in inputting a string using the %s format. If the input string is too long and exceeds the storage limit of the character array, the program execution error, so you can use the "field width" to limit the length of the input string. safer.
Since the type of a string constant is an array of char, it is interpreted as a pointer in the expression. That is, no matter how long the string is, pcStr always stores the address of the first character of the string, so a pointer to a string can be used to reference a string as a whole. such as:
Char *pcStr = "OK!";
Where pcStr is a character pointer variable, which is equivalent to
Static const char t376[] = "OK!";
Char *pcStr = t376;
The t376 is an internal variable name assigned by the compiler. The names of different compilers, different programs, and even the same source code may be different each time. Obviously, the programmer does not know the name of this array, which is an anonymous array variable. Obviously, the difference between the initialization character array storage string and the initialization pointer to the string is that the array name is a constant, and the pointer name is a variable, so most of the string operations are done by pointers.
It can be seen that "OK!" is the "array of char". It is also possible to prove the nature of the string or array by sizeof("OK!"). You can use "OK!" as the array variable name. See Listing 1.38 for details.
Listing 1.38 Example of using a string as an array variable name
1 #include
2 int main(int argc, char argv *[])
3 {
4 printf("OK! occupied space %d", sizeof("OK!")); // Output "OK!" occupied space, ie 4 bytes
5 printf("OK!'s address%x", "OK!"); // Output the address of "OK!"
6 printf("%c", *("OK!" + 1));; // Â Output the first element of "OK!", which is 'K'
7 printf("%c", "OK!"[0]); // Â Output the 0th element of "OK!", which is 'O'
8 printf("%d", "OK!"[3]); // Â Output the value of the third element of "OK!", ie '\0'
9 return 0;
10 }
Since the C language allows subscripting of pointers, Listing 1.38 (6~8) outputs the corresponding elements. Obviously, you can use this method to convert 0~15 to equivalent hexadecimal characters, as shown in Listing 1.39.
Program list  1.39 digit_to_charhex() conversion function sample program
1 char digit_to_hexchar(int digit)
2 {
3 return "0123456789ABCDEF"[digit];
4 }
When pcStr points to the first address of the string "OK!", *pcStr indicates that the value in the address space is 'O', ie pcStr[0]= 'O', pcStr[1]= 'K', pcStr[2 ]= '!',pcStr[3]= '\0', or *pcStr='O',*(pcStr+1)='K',*(pcStr+2)='!',*(pcStr+ 3) = '\0'.
The cigarette vape pod is usually called the electronic cigarette holder, a necessary part which installed upon electronic cigarette atomizer. The pod is made of oil cartridge or tank which stores the e-juice, and drip tip. Powered by battery, the e-liquid is heated by atomizer, finally forms into vapor which is look like the smoke. Generally speaking, the larger pod tank, the more liquid stored in the flammable, and the longer vaping times.
The pod can be various in flavors, fruits, nuts, tobacco....the strength can be 2-5% salt nic, or no nic.
The pod is consumable! It`s time to replace when the e-liquid in cartridge is ready to run out of, It's like replacing the ink cartridge in an inkjet printer when run out of it. Since 2018, the Electronic Cigarettes on the market are directly pod vape system, it is very simple and convenient, perfect alternative to box mode which is not only very heavy to carry but sldoand need refill oil frequently.
For some smokers who need for long-term use are more likely to buy liquid alone, fill themselves. Although this method looks more economical, it is not sanitary and have healthy threatens. It is easy to breed germs when using the same cigarette holder for a long time, finally enter human body through the mouth, causing bacterial infection. Therefore, for the sake of your health, please try to buy pod vape for replacement. Nothing is more precious than health!
Vape Pen,Disposable Vape Pod,Pod Mod,Vape Pod Pen,Vape Pod Kit
Shenzhen Axiswell Technology Co., Ltd , https://www.medhealthycare.com