找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 263|回复: 1

Question6.1:I had definition char a[6] in one source file,and in another I declared extern char *a

[复制链接]

210

主题

371

回帖

0

积分

管理员

积分
0
发表于 2013-7-8 16:39:29 | 显示全部楼层 |阅读模式

Q: I had the definition char a[6] in one source file, and in another I declared extern char *a. Why didn't it work?
A: In one source file you defined an array of characters and in the other you declared a pointer to characters. The declaration extern char *a does not declare an array and therefore does not match the actual definition. The type pointer-to-type-T is not the same as array-of-type-T. Use extern char a[].

210

主题

371

回帖

0

积分

管理员

积分
0
 楼主| 发表于 2013-7-8 16:48:48 | 显示全部楼层
问题:我在一个源文件中定义了一个char [6],在另一个文件中声明了extern char *a。为什么不行?
回答:你在一个文件中定义了一个字符数组,而在另一个文件中你声明了一个字符指针。对于声明extern char *不是声明的数组,因此不能和真正的定义相匹配。类型T的指针和类型T的数组并不是一样的类型。请使用extern char a[]。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

果子博客
扫码关注微信公众号

Archiver|手机版|小黑屋|风叶林

GMT+8, 2026-2-1 12:27 , Processed in 0.074659 second(s), 20 queries .

Powered by 风叶林

© 2001-2026 Discuz! Team.

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