(7.4)--7.4Pointerandstring.pdf

上传人:奉*** 文档编号:67738147 上传时间:2022-12-26 格式: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》由会员分享,可在线阅读,更多相关《(7.4)--7.4Pointerandstring.pdf(9页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

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.4psHello0String constantpHello0sEgchar s=Hello;char*ps=s;char*p=Hello;Poin

2、ter 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 end of 0.P

3、ointer and string7.4char s=Hello;char*p=Hello;char*ps=s;cinps;/Assume that the input is“abc”coutp;coutp+2;psabc0o0String constantpHello0s+2EgPointer and string7.4Eg1Write a program to implement the operation of taking a substring from a given string.Take a substring started from the 4thcharacter in

4、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;myboosk!0tPointer and string7.4Eg2Manipulation 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.4pP0p1P2Shanghai0Tiangin0Beijing0

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁