char variable

+1 ♦Avishka RJ ♦™ · January 30, 2015
See the below code; 

# include 
using namespace std; 
int main() 

char x = 'a' ; 
char y = 'x + 5' ; 
cout < return 0; 

This give 5 as output and 
when I typed 

# include 
using namespace std; 
int main() 

char x = 'a' ; 
char y = x + 5 ; 
cout < return 0; 

It gives "f" as output. 

What is this behavior of char variable??

Post a Reply

Replies

Oldest  Newest  Rating
0 Jay Deshaun · January 30, 2015
I didn't read it but it's similar to what you're talking about: Vars
0 Jay Deshaun · January 30, 2015
Yea, I see
+1 Troy Jones · January 30, 2015
char's are actually another representation of an int.  So it's just return the letter that is plus 5 of 'a', which appears to be 'f'.
  • 1

C++

107,151 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator