strcat函数疑点验证
来源:互联网 发布:服务器安装linux系统 编辑:程序博客网 时间:2024/06/06 07:06
原型
extern char *strcat(char *dest,char *src);
功能
把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')。
说明
src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。返回指向dest的指针。
疑点
dest没有有足够的空间会怎样?
验证代码
#include <stdio.h> int main(void){ char str1[6] = "hello"; char str2[6] = "world"; char str3[5] = "abc"; char str4[3] = "de"; int i =0; strcat(str1,str2); printf("str1 address=%a\n",str1); printf("str2=%s\n",str2); printf("strcat ---str1=%s\n",str1); printf("str1 address=%a\n",str1); str3[5] = 9; printf("back %d==%x\n",5,str3[5]); strcat(str3,str4); printf("str2=%s\n",str4); printf("strcat ---str1=%s\n",str3); for(i=0;i<7;i++) printf("%d==%x\n",i,str3[i]); return 0;}
linux下运行结果
str1 address=-0x1.f589208047d84p+1007
str2=world
strcat —str1=helloworld
str1 address=-0x1.f589208047d84p+1007
back 5==9
str2=de
strcat —str1=abcde
0==61
1==62
2==63
3==64
4==65
5==0
6==4
结论
程序运行成功,不会产生错误,所以自己写程序时,需要注意,防止越界发生。
0 0
- strcat函数疑点验证
- strcat函数
- strcat() 函数
- strcat函数
- strcat函数
- strcat函数
- strcat()函数
- strcat函数
- strcat函数
- strcat函数
- strcat函数
- strcat函数
- strcat 函数
- strcat 函数
- strcat 函数
- strcat函数
- strcat()函数
- strcat函数 strncat函数
- Google Guice 3.0开发
- Android数据存储方式——文件存储(内部和外部空间)
- 在eclipse中打开文件所在的目录
- 【DOM】node类型
- git仓库地址更换域名地址,即更换git托管
- strcat函数疑点验证
- Html调用摄像头并拍照
- 使用Maven管理Java项目
- MyBatis学习总结(四):MyBatis主配置文件
- MLY翻译 -- 1.Why Machine Learning Strategy?
- Mybatis实战之自定义TypeHandler处理枚举
- FilterDispatcher <<< is deprecated! Please use the new filters!
- c++第一次试验-1健康标准
- IntelliJ IDEA使用maven实现tomcat的热部署