Table of Contents
Typecasting in C/C++
Typecasting is an operation performed on one type of data to transform it into some other type supported by a particular programming language to serve some purpose in the program.
In this article we will be typecasting:
- int to char, and
- char to int
Typecasting int to char
When we typecast integer type of data into character type, the result is an ASCII representation of the corresponding digit. This means that you can’t produce exact representation of an integer into a character (i.e. 65 => ‘65’), rather you will be having its ASCII code in output (i.e. 65=> ‘A’).
Let’s look at an example below:
#include <iostream>
using std::cout;
using std::cin;
int main(){
cout<< char ( 65 ) <<"\n";
cout<< char ( 66 ) <<"\n";
cout<< char ( 67 ) <<"\n";
}
Here 65, 66, 67 are the integer values which are being typecast into character type using char() method. This approach is known as function-style typecast. Following is the output:

Typecasting char to int
On typecasting a character into an integer, again the result is the ASCII correspondence of that character (i.e. ‘A’ => 65). Following is a code snippet to demonstrate this.
#include <iostream>
using std::cout;
using std::cin;
int main(){
char a = 'A';
char b = 'B';
char c = 'C';
int num = (int) a;
cout<< num <<"\n";
num = (int) b;
cout<< num <<"\n";
num = (int) c;
cout<< num <<"\n";
}
The output looks like

Conclusion
In this article, we went through the concept of type casting and how does it practically look like when we type cast integer (int) type of data to character(char) type and vice versa, in C/C++ programming. As observed it’s to be noted that these types of data can’t be directly typecast, instead they are transformed into their ASCII representations first.