why does this keep giving me infinite loop

Started by
11 comments, last by neobie 19 years, 10 months ago
quote:Original post by smitty1276
That last bit ("an integer can''t hold a character") isn''t exactly true.

It''s perfectly legal to say:

int x = ''a'';printf("%c", x);


Is it not?


yeah, integers can hold chars. you can do integer math on chars as well. basically, just think of a char as an 8bit int, and all the ''x'' characters are just aliases for ASCII values. I really can''t think of anyway that they are different. Just remember, a char might not be able to hold any ol'' integer, because of the precision difference.

If I remember correctly, even in relatively type "safe" languages like Java, you can assign chars to ints without casting (but definitely would have to cast if you are going from int to char).


capn_midnight | Captain Midnight | deviantArt
ACM | SIGGRAPH | Generation5
"I''m tired of all this nonsense about beauty being only skin-deep. That''s deep enough. What do you want - an adorable pancreas?" -Jean Kerr

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Advertisement
You can hold the ASCII value of the character in an integer, yes, but iostreams aren''t overloaded to do that. If you write

int c = ''a'';
std::cout << c;

what are you going to get?
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
quote:Original post by smart_idiot
You can hold the ASCII value of the character in an integer, yes, but iostreams aren''t overloaded to do that. If you write

int c = ''a'';
std::cout << c;

what are you going to get?


The ASCII value of ''a'', in decimal
(Something like 61 or 41)

But it would work by typing
int c=''a'';
std::cout<<(char)c;

This topic is closed to new replies.

Advertisement