为什么它没有给出任何错误? [英] why it is not giving any error?

查看:81
本文介绍了为什么它没有给出任何错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经执行了以下程序,我期待这个程序中的一些错误

但它并没有给出任何错误! !!!!!!!!!!!!!!!!!!!!!!!

请有人解释一下吗?

#include< stdio。 h>

int main()

{

char a = 97;


"大家好+ printf(" a =%c\ n的价值,a);

返回0;

}


提前致谢

Prasanna KP

hi all,
I have executed the following program, I was expecting some errors in
the program but it didn''t give any ERRORS!!!!!!!!!!!!!!!!!!!!!!!!!!!
please can anybody explain me ?
#include<stdio.h>
int main()
{
char a=97;

"hello everyone"+printf("value of a=%c\n",a);
return 0;
}

Thanks in advance
Prasanna K P

推荐答案

prasi写道:
大家好,
我已经执行了以下程序,我期待在程序中出现一些错误,但它并没有给出任何错误!!!!!!!!!!!! !!!!!!!!!!!!!!!
请有人解释一下吗?
#include< stdio.h>
int main()
{
char a = 97;

" hello everyone" + printf(" a value of a =%c\ n,a);
返回0;
}
hi all,
I have executed the following program, I was expecting some errors in
the program but it didn''t give any ERRORS!!!!!!!!!!!!!!!!!!!!!!!!!!!
please can anybody explain me ?
#include<stdio.h>
int main()
{
char a=97;

"hello everyone"+printf("value of a=%c\n",a);
return 0;
}




将一个整数添加到一个字符指针是一个定义明确的操作(它在你的例子中没有副作用。)例如:


char * s =" xyz";


printf("%c\ n",*(s + 2));


将输出''z''。

八月



Adding an integer to a character pointer is a well defined operation (It
has no side effect in your example though.) For instance:

char *s = "xyz";

printf("%c\n", *(s + 2));

will output ''z''.
August


> #include< stdio.h>
> #include<stdio.h>
int main()
{
char a = 97;
int main()
{
char a=97;




你已将小数值97分配给char变量''a''。这个

infact在C中是合法的,因为字符使用ascii转换。不太确定

为什么,但如果你输入谷歌,ascii代码,你会看到

分配给每个角色的小数。



You have assigned a decimal value of 97 to char variable ''a''. This
infact is legal in C as characters use ascii conversion. Not too sure
about why, but if you type in google, "ascii code" you will see
decimals numbers assigned to each character.


prasi写道:
prasi wrote:
大家好,
我已经执行了以下程序,我在期待程序中的一些错误,但它并没有给出任何错误!!!!!!!!!!!!! !!!!!!!!!!!!!!
请有人解释一下吗?
#include< stdio.h>
int main()
{
char a = 97;

" hello everyone" + printf(" a value of a =%c\ n,a);
返回0;
}
hi all,
I have executed the following program, I was expecting some errors in
the program but it didn''t give any ERRORS!!!!!!!!!!!!!!!!!!!!!!!!!!!
please can anybody explain me ?
#include<stdio.h>
int main()
{
char a=97;

"hello everyone"+printf("value of a=%c\n",a);
return 0;
}




代码没有问题。


它是/傻/,但是那里'编译器没有义务检测

这个愚蠢的代码。


97作为一个字符值合法(不明智,但合法)。 />

将整数添加到指针是合法的 - 如果

它不是 - 那么C将是无用的 - 并且忽略计算值也是合法的并且

经常有用。


你可能会得到一些消息,如果你戳了你的编译器选项

更难。


-

Chris" electric hedgehog" Dollin

我知道三种:热,酷,什么时候开始调整?



There''s nothing wrong with the code.

It''s /stupid/, but there''s no obligation on a compiler to detect
stupid code.

97 is legal as a character value (ill-advised, but legal).

Adding integers to pointers is legal - C would be pretty useless if
it were not - and ignoring calculated values is also legal and
often useful.

You might get some messages if you poked your compiler options a
bit harder.

--
Chris "electric hedgehog" Dollin
"I know three kinds: hot, cool, and what-time-does-the-tune-start?"


这篇关于为什么它没有给出任何错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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