Character Data Type

                                              

                         Character Data Type

Character type variable can hold a single character and are declared by using the keyword char. As
there are singed and unsigned int (either short or long), in the same way there are signed and
unsigned chars; both occupy 1 byte each, but having different ranges. Unsigned characters have
values between 0 and 255, signed characters have values from –128 to 127.



In c# all characters internally represented as integer value of example following are ASCII values of characters.

A =65     a =97
B =66     b=98
C=67      c=99
and so on

  • Signed character                      -128 to 127     27
  • Unsigned character                        255            28   
Initialization of char type variable:-

Syntax:
char <variable name>;
char ch = 'a';
char chh ='b';

Example: a, b, g, S, j.

Here ch & chh are variable name & 'a' and 'A' are characters. 

Arithmetic on Char Type Variable:-

(i)Syntax:-



char ch='A';
ch=ch+32;
printf("Alphabet:%c\n",ch);          
printf("ASCII:%d",ch);


Output:  
  Alphabet:a
  ASCII:97

(ii)Syntax:-

char ch='a';
ch=ch+3;
printf("Alphabet:%c\n",ch);          
printf("ASCII:%d",ch);


Output:
  Alphabet:a
  ASCII:100

Runtime initialization of char type variable:-
scanf("%c",&ch);

Comments

Popular posts from this blog