天嵌 ARM开发社区

 找回密码
 注册
查看: 1151|回复: 1

帮我看看一个关于内存分配的小问题

[复制链接]
zr_714 发表于 2010-11-2 19:24:07 | 显示全部楼层 |阅读模式
1#include<stdio.h>
  2 #include<stdlib.h>
  3 #include<string.h>
  4 int main()
  5 {
  6 char *p1,*p2;
  7 p1=(char *)malloc(10*sizeof(char));
  8 strcpy(p1,"123456123456");
  9 //p1=p1-3;
10 //p2=p1;
11 //free(p2);
12 printf(":%s\n",p1);
13 printf(":%d\n",strlen(p1));
14 return 0;
15 }
~      
为什么我分配了10char的空间但是可以写进去13个字符啊 ?
TQ_guoxixiao 发表于 2012-5-9 15:15:39 | 显示全部楼层
溢出来,但是仍然可以写的。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-10-5 18:33 , Processed in 1.020442 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表