Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C++
void main()
{ clrscr();
int i;
cout<<"Enter i";
cin>>i;
cout<<i;
getch();
}


What I have tried:

When I tried to enter any alphabet,it gives same output i.e 7657
Posted
Updated 29-Aug-16 0:27am
v2
Comments
[no name] 29-Aug-16 5:25am    
alphabet? i is an int. How about you enter a number.

1 solution

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.:
C++
int i=0;


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[^]
 
Share this answer
 
Comments
Member 12708652 29-Aug-16 9:14am    
I know that it is int. But just for fun, i have entered alphabet. But output is coming 7657 only. Just want to know where the alphabet is stored and why this output is coming. Thanks for your reply.
[no name] 29-Aug-16 9:41am    
Read the answer very carefully. Learn to use a debugger.
Philippe Mori 29-Aug-16 18:21pm    
Read the documentation: istream::operator>>. You can call cin.good() for example to ensure that the input was read (and thus is valid).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900