1、Pointer and stringPointer and string7.4Each character in a string (including theending 0) is stored in sequence in thememory. If a character pointer points to thismemory, it can be used to manipulate thestring.Pointer and string7.4ps Hello0String constantp Hello0sEgchar s=Hello;char *ps=s;char *p=He
2、llo;Pointer and string7.4When using cin to input a string, the input from keyboard is actually stored in the memory pointed to by a pointer; when using cout to output a string, the characters in the memory pointed to by the pointer are actually taken out one by one and output to the screen until the
3、 end of 0.Pointer and string7.4char s=Hello; char *p=Hello;char *ps=s;cinps; /Assume that the input is “abc”coutp;coutp+2;ps abc0o0String constantp Hello0s+2EgPointer and string7.4Eg1 Write a program to implement the operation of taking a substring from a given string.Take a substring started from t
4、he 4thcharacter in the string my book!,and take 4 characters in all togenerate a new string.Pointer and string7.4int main()char s=my book!;char t5;int i, start=3, len=4;char *p=s+start;for (i=0; i len; i+)ti=pi; / Equivalent to *(t+i)=*(p+i)ti=0;coutThe substring is:tendl;return 0; m y b o os k ! 0tPointer and string7.4Eg2 Manipulation of multiple strings using array of pointers.int main() char *p3=Beijing, Tianjin, Shanghai;int i;for (i=0; i 3; i+)coutpiendl;return 0;Pointer and string7.4pP0p1P2 S h a n g h a i 0 T i a n g i n 0 B e i j i n g 0