Basic string operations and basic string operations
# Define _ CRT_SECURE_NO_WARNINGS # include <stdlib. h> # include <string. h> # include <stdio. h> // typical usage of a level-1 pointer // array int a [10] // string // 1 string of the C language that ends with zero // 2 no string type in the C Language simulate the memory allocation of the string // 3 string through the character array on the stack global zone (very important) // [] essence: it is the same as * p, but it conforms to the programmer's reading habits. // buf5 is a pointer, when the read-only constant buf5 is a constant pointer to analyze the memory, it ensures the safe release of the memory space pointed to by the buf. // Why? // P common pointer and memory first address difference // character array initialization void main51 () {// 1 specify the length of char buf2 [100] = {'A', 'B ', 'C', 'D'}; // 1-1char buf3 [2] = {'A', 'B', 'C', 'D '}; // if the number of initialization tasks is greater than the number of memory, the compilation fails. // 1-22 // The buf2 [4]-buf2 [99] 0 // 2 does not specify the length. C compiler will automatically help programmers find the number of elements char buf1 [] = {'A ', 'B', 'C', 'D'}; // buf1 is an array not a string ending with 0 printf ("buf2: % s \ n", buf2 ); printf ("buf2 [88]: % d \ n", buf2 [88]); printf ("hello .... \ n "); system (" pause "); return ;}// use a string to initialize the character array // strlen () length does not include 0 // sizeof () memory block size void main52 () {}// use the array subscript and pointer void main58 () {int I = 0; char * p = NULL; char buf5 [128] = "abcdefg"; // buffor (I = 0; I <strlen (buf5); I ++) {printf ("% c ", buf5 [I]);} p = buf5; // buf represents the address of the first element of the array for (I = 0; I <strlen (buf5); I ++) {p = p + I; printf ("% c", * p) ;}// buffor (I = 0; I <strlen (buf5); I ++) {printf ("% c", * (buf5 + I ));} // [] * derivation process // buf5 [I] ==> buf5 [0 + I] ;=> * (buf5 + I ); {// buf5 = buf5 + 1; // buf5 = 0x11;} printf ("hello .... \ n "); system (" pause ");}