Introduction to characters in C

Preview

Introduction to characters in C

Character Constant:

Character constant is a single characters enclosed within the pair of single quotes (‘). It can contain alphabet, digit, special character and space.

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

 



Best Books of Computer Science





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