求指点!

muku9527 2011-08-23 02:54:16
#include"stdio.h"

int main()
{
__int16 a=324;
__int16 b=68;
char f='A';
printf("a=%c\n",a);
printf("b=%c\n",b);
printf("sizeof(f)=%d\n",sizeof (f));
printf("sizeof('A')=%d\n",sizeof ('A'));
return 0;
}//这个地方sizeof (f)=1;sizeof ('A')=4为什么?
...全文
76 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yjq1987 2011-08-23
  • 打赏
  • 举报
回复
vs2010编译运行两个输出的都是1啊。
muku9527 2011-08-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 pengzhixi 的回复:]
An integer character constant has type int. The value of an integer character constant containing a single character that maps to a single-byte execution character is the numerical value of the repres……
[/Quote]

果断给力,谢谢!
zsc_ericluo 2011-08-23
  • 打赏
  • 举报
回复
你那里是%d输出,可能你那个编译器默认int是4字节,所以结果是4咯!
CJacky++ 2011-08-23
  • 打赏
  • 举报
回复
Mark.
pengzhixi 2011-08-23
  • 打赏
  • 举报
回复
如果是C++也许结果就是1而不是4了。
pengzhixi 2011-08-23
  • 打赏
  • 举报
回复
An integer character constant has type int. The value of an integer character constant containing a single character that maps to a single-byte execution character is the numerical value of the representation of the mapped character interpreted as an integer. The value of an integer character constant containing more than one character (e.g.,'ab'), or containing a character or escape sequence that does not map to a single-byte execution character, is implementation-defined.


C标准对字符字面量的规定是 has type int.
cunyan_0519 2011-08-23
  • 打赏
  • 举报
回复
char f='A';说明f是字符型的,肯定长度为1个字节的。而'A'按整型输出的。

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧