Convert character to number in c++

Started by
11 comments, last by smart_idiot 18 years, 10 months ago
char c = '4';
int i = c - '0';
cout <
Advertisement
Quote:Original post by Anonymous Poster
char c = '4';
int i = c - '0';
cout <


Nice. Reminds me of the old converting decimal to hex by indexing into an array of "1234567890ABCDEF".
Not only does this do the wrong thing, it crashes (for me, anyway)

int main() {  static const int c = 0;  const_cast<int &>(c) = 42; }


That'll teach me to modify read-only memory.
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.

This topic is closed to new replies.

Advertisement