An array of string pointers, that is, each item in the array is a pointer to a string.
Definition: char* s[3]; that is, an array of three pointers, written in this form, can also be better understood, that is, the type of array stored is char*.
Another point: The array name generally refers to the first address, so the first element of the array address &s[0], because S[0] is a pointer, so the array name is a pointer to the pointer, char** p=s;
Then the operation of the array is as follows:
intMain () {Char* a="hello!"; Char* b="pangpang!"; Char* c="How is it ?"; Char* s[3]={a,b,c}; intlen=sizeof(s)/sizeof(Char*); Char* * p=s; for(intI=0; i<len;++i) {cout<<p[i]<<Endl; } return 0;}
The length of sizeof (s) is the total number of bytes in the array, 3 pointers is 12 bytes (32-bit machine), so that the length of the pointer is 4, it can be concluded that the length of the array is 12/4=3
Or so the output is also possible:
intMain () {Char* a="hello!"; Char* b="pangpang!"; Char* c="How is it ?"; Char* s[4]={a,b,c,null}; Char* * p=s; for(p;*p!=null;++p) {cout<<*p<<Endl; } return 0;}
Array of string pointers, pointers to pointers