C++ Char Data Types (original) (raw)

Last Updated : 11 Oct, 2025

A Char datatype is a datatype that is used to store a single character. It is always enclosed within a single quote (' ').

C++ `

#include using namespace std;

int main() {

char c = 'g';
cout << c;
return 0;

}

`

ASCII Value

ASCII Value stands for American Standard Code for Information Interchange. It is used to represent the numeric value of all the characters.

Convert Character Value to Corresponding ASCII Value

To convert a character to ASCII value we have to typecast it using int(character) to get the corresponding numeric value.

C++ `

#include using namespace std;

int main() { char c = 'g'; cout << "The Corresponding ASCII value of 'g' : "; cout << int(c) << endl;

c = 'A';
cout << "The Corresponding ASCII value of 'A' : ";
cout << int(c) << endl;
return 0;

}

`

Output

The Corresponding ASCII value of 'g' : 103 The Corresponding ASCII value of 'A' : 65

Convert ASCII Value to Corresponding Character Value

To convert an ASCII value to a corresponding Character value we have to typecast it usingchar(int) to get the corresponding character value.

C++ `

#include using namespace std;

int main() { int x = 53; cout << "The Corresponding character value of x is : "; cout << char(x) << endl;

x = 65;
cout << "The Corresponding character value of x is : ";
cout << char(x) << endl;

x = 97;
cout << "The Corresponding character value of x is : ";
cout << char(x) << endl;
return 0;

}

`

Output

The Corresponding character value of x is : 5 The Corresponding character value of x is : A The Corresponding character value of x is : a

Escape Sequence in C++

Escape sequences are characters that determine how the line should be printed on the output window. The escape sequence always begins with a backslash '\' (also known as an escape character). Some Examples of Escape Sequences are mentioned below:

S. No. **Escape Sequences **Character
1. \n Newline
2. \\ Backslash
3. \t Horizontal Tab
4. \v Vertical Tab
5. \0 Null Character

C++ `

#include using namespace std;

int main() { char a = 'G';

// horizontal tab
char b = '\t';
char c = 'F';
char d = '\t';
char e = 'G';

// new line
char f = '\n';
string s = "is the best";
cout << a << b << c << d << e << f << s;
return 0;

}

`