是一个不确定的循环? [英] y an indefinate loop??

查看:91
本文介绍了是一个不确定的循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

字符常量的范围是-128到127 ......但是在以下程序中....



main()

{

char x;

for(x = -128; x< = 127; x ++)

{

printf(" \ n%d%c",x,x);

}

getch();

}


程序进入无限循环,同时打印ascii值&从-128到127的字符。虽然程序确实打印输出但它是一个不定循环的形式。为什么程序进入一个不定的循环?


为(b = -128; x <= 126; x ++)
/>


以上程序打印ascii值&字符从-128到126而没有进入一个不确定的循环。


为什么程序进入一个不确定的循环来指定限制为-128到127而它没有在-128到126的情况下?




我们观察到按下ctrl + num lk / scroll lk我们可以逃脱正在进行的无限循环。这是否会发生....





谢谢你... ...

the range of character constants is from -128 to 127....but in the following program....


main( )
{
char x;
for(x= -128; x<=127;x++)
{
printf("\n %d %c",x,x);
}
getch( );
}


the program gets into an indefinate loop while printing the ascii value & the character from -128 to 127.Altough the program does print the output but it is in the form of an indefinate loop.why does the program get into an indefinate loop?



in the above program if we alter the for statement as-


for(x= -128;x<=126;x++)


the above program prints the ascii value & the characters from -128 to 126 without getting into an indefinate loop.


why does the program enter an indefinate loop on specifing the limits as -128 to 127 while it doesnt in the case of -128 to 126?





Also we observed that on pressing ctrl+num lk/scroll lk we can escape an indefinate loop in progress.y does this happen....





thank u......

推荐答案

如果字符只能保存[-128,127]范围内的值,那么

的值是多少另外127 + 1?


亲切的问候,


Jos
If characters can only hold values in the range [-128, 127] what would the value
be of the addition 127+1?

kind regards,

Jos


indefinIte未定义;无限是无穷无尽的,什么流浪'y'是我无法解读的。查看已签名的二进制表示。
indefinIte is not defined; infinite is endless, and what stray ''y'' is I could not decipher yet. Look at binary representation of signeds.


127 + 1将溢出,值再次返回-127。

这就是为什么它是无限循环。


Raghu
127+1 will overflow and the value goes back to -127 again.
Thats why it is infinite loop.

Raghu


这篇关于是一个不确定的循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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