Convert Integer to Char

Convert Integer to Char in C++ (5 Programs)

BeginnerTopic: String Conversion Programs
Back

C++ Convert Integer to Char Program

This program helps you to learn the fundamental structure and syntax of C++ programming.

Try This Code
#include <iostream>
using namespace std;

int main() {
    int num = 65;
    
    // Method 1: Direct casting
    char ch1 = (char)num;
    
    // Method 2: Using static_cast
    char ch2 = static_cast<char>(num);
    
    cout << "Integer: " << num << endl;
    cout << "Character (method 1): " << ch1 << endl;
    cout << "Character (method 2): " << ch2 << endl;
    
    return 0;
}
Output
Integer: 65
Character (method 1): A
Character (method 2): A

Understanding Convert Integer to Char

This program demonstrates 5 different methods to convert an integer to a character: direct casting, static_cast, using ASCII values, using char arithmetic, and using sprintf.

Note: To write and run C++ programs, you need to set up the local environment on your computer. Refer to the complete article Setting up C++ Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your C++ programs.

Table of Contents