This post will discuss how to convert a char to ASCII code in C++.

A simple solution to convert a char to ASCII code in C++ is using type-casting. Here’s an example of its usage:

Download  Run Code

 
Alternatively, we can implicitly convert a char to ASCII code by assigning the char to an int. This works since a char is already a number.

Download  Run Code

 
C++ also offers four types of casting operatorsstatic_cast, dynamic_cast, reinterpret_cast, and const_cast. To make the conversion safe and explicit, consider using static_cast.

Download  Run Code

That’s all about converting a char to ASCII code in C++.