结构体中数组的访问,为什么不越界
时间:2010-09-09
来源:互联网
truct test {
int n;
int a[1];
int b;
};
struct test test;
test.n = 3;
test.a[0] = 1;
test.a[1] = 2;
test.a[2] = 3;
test.a[3] = 4;
printf("%d, %d, %d, %d, %d\n", test.n, test.a[0], test.a[1],
test.a[2], test.a[3]);
printf("%zd\n", sizeof(test));
printf("%zd\n", sizeof(struct test));
结果:
3, 1, 2, 3, 4
12
12
为什么不出错呢
int n;
int a[1];
int b;
};
struct test test;
test.n = 3;
test.a[0] = 1;
test.a[1] = 2;
test.a[2] = 3;
test.a[3] = 4;
printf("%d, %d, %d, %d, %d\n", test.n, test.a[0], test.a[1],
test.a[2], test.a[3]);
printf("%zd\n", sizeof(test));
printf("%zd\n", sizeof(struct test));
结果:
3, 1, 2, 3, 4
12
12
为什么不出错呢
作者: yunyue520 发布时间: 2010-09-09
如果越界就能报错的话,那么越界也就不会是令大家头痛的问题了
作者: liwangli1983 发布时间: 2010-09-09
已经越界了。C对越界是不做检查的。随你怎么越,爱咋越咋越。
越到操作系统的分页保护时,给你个段错误。
你的进程就over了。
越到操作系统的分页保护时,给你个段错误。
你的进程就over了。
作者: zhangsuozhu 发布时间: 2010-09-09
这个世界不只存在你看得见的那一小小小部分。
实际发生但你没看见的事,多着呢。
实际发生但你没看见的事,多着呢。
作者: langue 发布时间: 2010-09-09
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28