Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • C++ Data Types
  • C++ Input/Output
  • C++ Arrays
  • C++ Pointers
  • C++ OOPs
  • C++ STL
  • C++ Interview Questions
  • C++ Programs
  • C++ Cheatsheet
  • C++ MCQ
  • C++ Projects
  • C++ Exception Handling
  • C++ Memory Management
Open In App
Next Article:
C++ Char Data Types
Next article icon

C++ Char Data Types

Last Updated : 29 Nov, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

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

Syntax: 

Char variable;

Example:

C++
// C++ Program demonstrate // Use of char #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

To know more about it, refer to the article - ASCII table.

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.

Example: 

C++
// C++ Program to convert // Char to ASCII value #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.

Example:

C++
// C++ Program to convert // ASCII value to character #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

Example:

C++
// C++ Program to demonstrate // Use of Escape Sequence #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

Next Article
C++ Char Data Types

R

raj2002
Improve
Article Tags :
  • Technical Scripter
  • C++
  • Technical Scripter 2022
  • cpp-data-types
Practice Tags :
  • CPP

Similar Reads

    C++ Data Types
    Data types specify the type of data that a variable can store. Whenever a variable is defined in C++, the compiler allocates some memory for that variable based on the data type with which it is declared as every data type requires a different amount of memory.C++ supports a wide variety of data typ
    7 min read
    char8_t Data Type in C++ 20
    The most recent version of the C++ programming language, C++20, was introduced in the year 2020. The char8_t data type is one of the new features added to C++20. This data type was created especially to display UTF-8 encoded characters. Let's understand what char8_t is and how is it different from o
    3 min read
    COBOL - Data Types
    A Datatype is a classification by the programmer to tell the compiler/interpreter how data will be used inside a program. For example, the roll number of the student defined as the number will take input as a number only if other values are supplied instead of the number it will raise an abend insid
    4 min read
    SAP ABAP | Data Types
    Before Understanding the Data type first understand the Data object. Data objects are variables that we declare in the program. It occupies some memory where you can store the data from external sources. Data can be of different types, so data types are responsible for defining the type of data of t
    6 min read
    C++ Compound Data Types Quiz
    Built-in data types cannot store all the information in an easily accessible and organized way. That is why C++ provides compound data types such as arrays, pointers, strings, etc. that are derived from the built-in data types and provide different way to use them. Good understanding of compound dat
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences