cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
c++ with char
c++ with char
Oct 23, 2010 at 11:03am UTC
Nosce
(2)
Hi, I need a lil help with my homework.
the main function looks like this:
int main ()
{ char a; a='A';
char b; b=2;
char c = a+b;
cout << "c=" << c;
return 0;
}
When I run the program I get c=C
Can somebody explain why that is?
Oct 23, 2010 at 11:09am UTC
hamsterman
(4538)
Every char is represented by a number. see
http://www.cplusplus.com/doc/ascii/
'A' = 65, 'C' = 67, so 'A' + 2 = 'C'.
Oct 23, 2010 at 11:11am UTC
Nosce
(2)
Thank you :)
Topic archived. No new replies allowed.