Dremendo Tag Line

Character Variable in C++ Programming

C++ Basic Concepts

In this lesson, we will learn about Character variable in C++ programming with the help of some examples. We will also play a quiz on it at the end.

What is Character Variable

A Character variable in C++ programming can store any single character enclosed within single quotes. To declare a variable of type Character we use the keyword char (pronounced as kar).

video-poster

Syntax of Declaring Character Variable in C++

char variable_name;

Here char is used for declaring Character data type and variable_name is the name of variable (you can use any name of your choice for example: a, b, c, alpha, etc.) and ; is used for line terminator (end of line).

Now let's see some examples for more understanding.

Example 1

Declare a character variable x.

char x;

Example 2

Declare 3 character variables x, y, and z to assign 3 different characters in it.

char x='A', y='5', z='#';

Note: A character can be anything, it can be an alphabet or digit or any other symbol, but it must be single in quantity.

Example 3

Declare a character variable x and assign the character '$' and change it value to @ in the next line.

char x = '$';
x = '@'; //now the new value of x is @

Test Your Knowledge


You Scored :

Percentage :