字符常量 [英] Character Constants

查看:82
本文介绍了字符常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于字符常量是一个int值,用单引号表示为字符

,所以它被视为1字节整数现在看看

以下代码段。


#include< stdio.h>

int main(无效)

{

char a =''Abbc'';

printf("%c",a);


返回0;

}


请解释如何解释初始化,编译时

给出警告多字符字符常量。但运行没有

错误也可能是单引号中的最后一个字符是

存储在一个。

解决方案

我在TC2.0中编译时收到错误消息

错误:函数main中字符常量太长


Akhil写道:

char a =''Abbc'';
请解释如何解释初始化,




初始化被解释为

编译器想要的任何方式。 />
C标准没有定义它。


-

pete

Akhil写道:

由于字符常量是一个以单引号表示为字符的int值,因此它被视为1字节整数现在看起来在
以下片段。

#include< stdio.h>
int main(无效)
{/ a> char a =''Abbc'' ;
printf("%c",a);

返回0;
}
请解释在编译时如何解释初始化它给出了一个警告多字符字符常量。但运行没有
错误也可能是单引号中的最后一个字符存储在a。




有关初始化的说明,请参阅你的编译器文档,

标准表示它的实现是定义的。


至于警告,你的编译器很好,让你知道

你可能正在做一些你不想要的事情。我还告诉我

隐式转换已经溢出。

-

BR,弗拉基米尔


我是工人的朋友,我宁愿做他的朋友

而不是一个。

- Clarence Darrow


Since a character constant is an int value represented as a character
in single quotes,so it is treated as a 1 byte integer now look at the
following snippet.

#include<stdio.h>
int main(void)
{
char a=''Abbc'';
printf("%c",a);

return 0;
}

Please explain how the initialization is interpreted,on compilation it
gives a warning "multi-character character constant" but runs without
error also possibly the last character within the single quotes is
being stored in a.

解决方案

I got an error message when compile it in TC2.0
Error: Character constant too long in function main


Akhil wrote:

char a=''Abbc''; Please explain how the initialization is interpreted,



The initialization is interpreted
any way that the compiler wants to.
The C standard doesn''t define it.

--
pete


Akhil wrote:

Since a character constant is an int value represented as a character
in single quotes,so it is treated as a 1 byte integer now look at the
following snippet.

#include<stdio.h>
int main(void)
{
char a=''Abbc'';
printf("%c",a);

return 0;
}

Please explain how the initialization is interpreted,on compilation it
gives a warning "multi-character character constant" but runs without
error also possibly the last character within the single quotes is
being stored in a.



For explanation of initialisation, refer to your compiler documentation,
as Standard says it''s implementation defined.

As for the warning, your compiler is just being nice, letting you know
that you may be doing something you don''t want. Mine also tells me that
implicit conversion has overflown.
--
BR, Vladimir

I am a friend of the working man, and I would rather be his friend
than be one.
-- Clarence Darrow


这篇关于字符常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆