The
char is a data type and it is also a keyword which is used to declare a
variable as a character constant. The char data type occupies 1 byte (8 Bits)
in memory. The range of char data type is -128 to 127.
By default char data
type is signed if you want unsigned char data type you must use unsigned
keyword at the beginning of the char. The range of unsigned char is 0 to 255.
The format specifier of the char data type is ‘%c’.
Synatx:
char variable_name;
ex:
char name, ch;
Program: Enter 3 Characters and print it on the screen.
#include<stdio.h>
#include<conio.h>
void main()
{
char a, b, c;
printf(“Enter 3
Characters : “);
scanf(“%c%c%c”,
&a, &b, &c);
printf(“Characters are
: %c %c %c”, a, b, c);
getch();
}
output:
Enter 3 Characters : X Y Z
Characters are : X Y Z
No comments:
Post a Comment