GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • C++ Tutorial
  • Interview Questions
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • OOP
  • Exception Handling
  • STL
  • DSA C++
  • Introduction2 min read
  • Data Types4 min read
  • Variables4 min read
  • Operators9 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — C++ Char Data Types - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • C++ Tutorial
  • Interview Questions
  • Examples
  • Quizzes
  • Projects
  • Cheatsheet
  • OOP
  • Exception Handling
  • STL
  • DSA C++

C++ Char Data Types

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 <iostream>
using namespace std;

int main()
{

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

Output
g

ASCII Value

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

  • ASCII Range of 'a' to 'z' =  97-122
  • ASCII Range of 'A' to 'Z' =  65-90
  • ASCII Range of '0' to '9' = 48-57

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 <iostream>
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 using char(int) to get the corresponding character value.

C++
#include <iostream>
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 SequencesCharacter
1.\nNewline
2.\\Backslash
3.\tHorizontal Tab
4.\vVertical Tab
5.\0Null Character
C++
#include <iostream>
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;
}

Output
G	F	G
is the best

To know more about it, refer to the article - C++ Escape Sequences


Comment

Explore

    C++ Basics
    • Introduction2 min read
    • Data Types4 min read
    • Variables4 min read
    • Operators9 min read
    • Basic Input / Output2 min read
    • Control Flow Statements15+ min read
    • Loops7 min read
    • Functions5 min read
    • Arrays5 min read
    Core Concepts
    • Pointers and References4 min read
    • new and delete Operators5 min read
    • Templates in C++7 min read
    • Struct Union Enum3 min read
    • Exception Handling5 min read
    • File Handling9 min read
    • Multithreading6 min read
    • Namespace5 min read
    OOP
    • OOP Concepts10 min read
    • Inheritance6 min read
    • Polymorphism5 min read
    • Encapsulation3 min read
    • Abstraction4 min read
    Standard Template Library(STL)
    • STL3 min read
    • Container Library3 min read
    • Iterators10 min read
    • Algorithm Library3 min read
    Practice & Problems
    • Interview Questions15+ min read
    • Programming Examples4 min read
    Courses
    • Placement 360 Course2 min read
    • DSA and System Design Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.