Recently looking at C language, in the pointer this piece has encountered the trouble, especially the string pointer this piece, simple record under.
string pointers
1 voidMain ()2 {3 Char*p ="tasklist";//pointer, string pointer4printf"%d",sizeof(P));5printf"\n%d",sizeof("tasklist"));//9 characters tasklist6 //p Stores the first address of the constant string "tasklist", which is the address of the T character7 //*p = ' 1 '//cannot assign a value, Tasklist is a pointer, the pointer is a constant cannot be assigned. 8 9printf"\n%c", *p);//TTenprintf"\n%c", * (p+1));//a One A GetChar (); -}
Array of string pointers
1 //array of string pointers2 voidmain2 ()3 {4 //pointer array p Stores elements that are pointer types, that is, top,ll,ls are pointer types (constants cannot be assigned values)5 Char*p[] = {"Top","ll","ls"};6 intL =sizeof(p)/sizeof(Char*);7 //printf ("%d", sizeof (p)/sizeof (char *));//How many elements of an array8 inti =0;9 Ten for(; i < L; i++) { One //I=1 For example, P[i] is the first address of top pointing to top. That is, the address of the T character Aprintf"%c\n", * (P[i]));//Print out character T -printf"%x,%s\n", P[i],p[i]); - } the -System"Pause"); - -}
C-language string pointers