Cpp - Output Characters and Character Codes

Introduction

The >> operator interprets a number of type char as the character code and outputs the corresponding character:

char ch = '0'; 
cout << ch << ' ' << 'A'; 
// 0 A 

It is possible to output the character code for a character.

The character code is stored in an int variable and the variable is then output.

int code = '0'; 
cout << code;         // Output: 48 

The '0' character is represented by ASCII Code 48. The program on the opposite page contains further examples.