Tagged with: C + + size RET Initialize Hello and char C99 turn
1. Each string is terminated with '/' at the end, so that we can easily find the end of the string.
1 Char str[]; 2 strcpy (str,"0123456789"); // Error: Array is out of bounds. The actual length of "0123456789" is 11 bytes
Note: Remember the null character at the end of the string to prevent the array from overstepping.
2. C + + places a constant string in a separate memory area
In order to save memory, C + + places a constant string in a separate memory area. When several pointers are assigned to the same constant string, they actually point to the same memory address . But initializing arrays with constant memory is a different situation.
1 intMainintargcChar*argv[])2 {3 Charstr1[]="Hello World";4 Charstr2[]="Hello World";5 6 Char*str3="Hello World";7 Char*str4="Hello World";8 9 if(str1==str2)Tencout<<"str1 and str2 are same\n"; One Else Acout<<"str1 and str2 is not same\n"; - - if(str3==STR4) thecout<<"STR3 and STR4 are same\m"; - Else -cout<<"STR3 and STR4 is not same\n"; - + return 0; - } + //Output: A //str1 and str2 is not same at //STR3 and STR4 are same
C + +--string