为什么7657会输出? [英] Why is 7657 coming in output?

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

问题描述

void main()
{ clrscr();
int i;
cout<<"Enter i";
cin>>i;
cout<<i;
getch();
}





我的尝试:



当我尝试输入任何字母时,它给出相同的输出,即7657



What I have tried:

When I tried to enter any alphabet,it gives same output i.e 7657

推荐答案

C ++非常具体......



据我记得, 未初始化的变量可能导致不可预测的结果!!! 



因此,您必须为设置初始值i 变量。你可以在一行内完成,即:

C++ is very specific...

As far as i remember,   uninitialized variables can cause unpredictable results!!! 

So, you have to set initial value for i variable. You can do it within single line, i.e.:
int i=0;





我建议阅读 type casting [ ^ ]。您应该将char转换为整数值。您可以使用 atoi功能 [ ^ ]。



如需了解更多详情,请阅读此内容:

变量和类型 - C ++教程 [ ^ ]



I'd suggest to read about type casting[^]. You should convert char into integer value. You can achieve that by using atoi function[^].

For further details, please read this:
Variables and types - C++ Tutorials[^]


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

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