Introduction to characters in C

Introduction to characters in C

Character Constant:

Character constant is a single characters enclosed within the pair of single quotes (‘). It can contain any alphabet, digit, special character as well as space. We can’t store more than one character in it.

Example

‘A’ , ‘5’ , ‘$’ etc.

Character Variable

Character variable is a variable of char data type.

Example : char gender;

Character Variable Initialization:

Character variable can be initialized just like variables of other data types.

Example: char gender=’F’;



Program for reading and displaying character variable.
#include<stdio.h>
int main()
{
char n;
printf(“\nEnter a character=”);
scanf(“%c”,&n);
printf(“\ncharacter=%c”,n);
return(0);
}
Output
Enter a character=k
character=k

 





Spread the love
Lesson tags: declare character variable in c, initialize a character variable in c, read and display character variable, what is a character variable, what is character constant
Back to: C Programming Language
Spread the love