C++: Printing the ASCII value of a char

This entry is part 7 of 61 in the series C++

Using iostream cout, we can print out the integer value of an ASCII char.

If you check the ascii value of b, it’s decimal value is 98. ┬áThis can be shown in the program below where we define an integer b with the char ‘b’.

#include <iostream>
using namespace std;

void main()

	int b = 'b';   // note: char implicitly converted to int
	char c = 'c';

	cout << 'a' << endl;
	cout << b << endl;
	cout << c << endl;



Series Navigation<< C++: Iostream
C++: The string class >>