Cpp - Data Type char Type

Introduction

char and wchar_t types are used for saving character codes.

A character code is an integer associated with each character.

The letter A is represented by code 65, for example.

The character set defines which code represents a certain character.

The char type stores character codes in one byte (8 bits).

The wchar_t (wide character type) type comprises at least 2 bytes (16 bits) and can store modern Unicode characters.

Unicode is a 16-bit code containing codes for approximately 35,000 characters in 24 languages.

Examples for character constants

Constant

Character

Constant Value
(ASCII code decimal)
'A'
Capital A
65
'a'
Lowercase a
97
' '
Blank
32
'.'
Dot
46
'0'
Digit 0
48
'\0'
Terminating null character
0

A character constant is a character enclosed in single quotes.

'A'        // Type: char 

The numerical value is the character code representing the character.

The constant 'A' has a value of 65 in ASCII code.

Related Topics

Exercise