收藏 分享(赏)

(7.4)--7.4Pointerandstring.pdf

上传人:职教中心 文档编号:13706923 上传时间:2022-10-11 格式:PDF 页数:9 大小:626.07KB
下载 相关 举报
(7.4)--7.4Pointerandstring.pdf_第1页
第1页 / 共9页
(7.4)--7.4Pointerandstring.pdf_第2页
第2页 / 共9页
(7.4)--7.4Pointerandstring.pdf_第3页
第3页 / 共9页
亲,该文档总共9页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报