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).
Syntax of Declaring Character Variable in C
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.
Declare a character variable x.
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.
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
Attempt the multiple choice quiz to check if the lesson is adequately clear to you.