找回密码
 立即注册
搜索
热搜: 活动 通知
查看: 684|回复: 2

检测点8-14

[复制链接]

630

主题

370

回帖

2538

积分

管理员

积分
2538
发表于 2026-3-7 19:41:53 | 显示全部楼层 |阅读模式
检测点8-14

1.对于以下声明:
int a [], b [sizeof (int) * 10], c [40];
float d [], e [40];
请问:哪些对象的类型是兼容的?b和c的类型在什么条件下是兼容的?
答:a和b、a和c、d和e是兼容的,但b和c只有在int类型的长度为4时才兼容。

2.下例中,指针p1、p2和p3所指向的类型是否兼容?为什么?
int (* p1) [], (* p2) [], (* p3) [22];
答:兼容。因为p1和p2指向的类型相同,都是未指定大小的数组。p3指向的类型是具有常量大小的数组,与未指定大小的数组兼容。

3.对于声明:
int n = 3, a [n], b [n + 1], c [33];
哪些对象的类型是兼容的?
答:a和b、a和c、b和c都是兼容的。

4.表达式sizeof (int [])合法吗?为什么?
答:不合法。sizeof运算符的操作数不能是不完整类型。

5.表达式sizeof (int (*) [])合法吗?为什么?
答:合法。int (*) []是指针,尽管指向的类型不完整,但指针本身是完整类型。

0

主题

5

回帖

24

积分

新手上路

积分
24
发表于 2026-10-17 12:53:18 | 显示全部楼层
For two array types to be compatible, both shall have compatible element types, and if both size specifiers are present and are integer constant expressions, then both size specifiers shall have the same constant value.
If one size specifier is present as an integer constant expression and the other is present and is not an integer constant expression(也就是一个固定数组,一个 VLA)→ 类型不兼容,第三题还是变长数组吗?

点评

VLA和固定长度数组是兼容的。参见“Compatible type and composite type”一节。  发表于 2026-10-17 19:44
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|鼠侠网 ( 吉ICP备19001332号 )

GMT+8, 2026-11-15 07:25 , Processed in 0.985904 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

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