Character Set in C: Uses, Types & ASCII Values

Jasmine Grover logo

Jasmine Grover Content Strategy Manager

Content Strategy Manager

In C programming, a charactеr refers to thе collеction of charactеrs that can bе usеd to writе C programs. C usеs a charactеr sеt known as thе ASCII (American Standard Codе for Information Intеrchangе) charactеr sеt, which is a widеly-usеd charactеr еncoding standard. 

  • The C programming language was created to provide effective computing utility for programmers.
  • It supports 265 valid characters. It comprises various kinds of characters such as alphabets, digits, white spaces, etc. 
  • It provides a simple way for programmers to express operations using a standardised set of symbols. 

Key Terms- Characters, ASCII, Programming, Digits, Values, Alphabets, Symbols


Character Set C in a Programming Language 

[Click Here for Sample Questions]

In computer programming, code points or numericals are assigned to represent specific characters. A set of values which represent different characters is called a character set. 

  • Different programming languages have different valid codings and thus support different sets of characters. 
  • C can be combined to form words, phrases and sentences. 
  • Understanding the character set is crucial for computer science students as it forms the building blocks of each C program. 

Uses of Character Set in C 

[Click Here for Sample Questions]

The uses of Character Set in C are mentioned below:

  • The character set supports a wide range of commonly used alphabets to represent the source programme.
  • Many symbols such as '+', ()* & ^ are usually required in computers. 
  • So the programming language provides ASCII values for a set of commonly used symbols as well.
  • By using the character set we can form words by combining different alphabets and in turn we may create phrases & sentences as well.

Read More: Introduction To Array​


ASCII Values

[Click Here for Sample Questions]

The American Standard Code for Information Interchange (ASCII) values are numerical codes which are programmed to represent a specific character in the C programming language. 

  • For example, the ASCII value 97 denotes a lowercase 'a'. 
  • Similarly, each character has a corresponding ASCII Value which can be coded up to 8 bits. 
  • ASCII uses seven-digit binary numbers- i.e., numbers consisting of various sequences of 0's and 1's. 

Since there are 128 different possible combinations of seven 0's and 1's, the code can represent 128 different characters.

  • Control characters- In computer programming there are certain characters which are used to initiate or execute an action rather than printing graphic characters on the screen.
  • In ASCII standard, there are 33 control characters such as escape, new line non-breaking space, tab character, etc. 
  • Printable characters- Characters which represent and display text forms of characters on the screen are called printable characters. 
  • Printable characters include alphabets, digits, punctuation marks such as full stop, brackets, commas, question marks, etc. They range from 32 to 126 in ASCII Values. 

Given is a chart of printable characters in hex and decimal format. 

HEX DEC CHARACTER HEX DEC CHARACTER HEX DEC CHARACTER
0x20 32 <SPACE> 0x40 64 @ 0x60 96 `
0x21 33 ! 0x41 65 A 0x61 97 a
0x22 34 0x42 66 B 0x62 98 b
0x23 35 # 0x43 67 C 0x63 99 c
0x24 36 $ 0x44 68 D 0x64 100 d
0x25 37 % 0x45 69 E 0x65 101 e
0x26 38 & 0x46 70 F 0x66 102 f
0x27 39 0x47 71 G 0x67 103 g
0x28 40 ( 0x48 72 H 0x68 104 h
0x29 41 ) 0x49 73 I 0x69 105 i
0x2A 42 * 0x4A 74 J 0x6A 106 j
0x2B 43 + 0x4B 75 K 0x6B 107 k
0x2C 44 , 0x4C 76 L 0x6C 108 l
0x2D 45  0x4D 77 M 0x6D 109 m
0x2E 46 . 0x4E 78 N 0x6E 110 n
0x2F 47 / 0x4F 79 O 0x6F 111 o
0x30 48 0 0x50 80 P 0x70 112 p
0x31 49 1 0x51 81 Q 0x71 113 q
0x32 50 2 0x52 82 R 0x72 114 r
0x33 51 3 0x53 83 S 0x73 115 s
0x34 52 4 0x54 84 T 0x74 116 t
0x35 53 5 0x55 85 U 0x75 117 u
0x36 54 6 0x56 86 V 0x76 118 v
0x37 55 7 0x57 87 W 0x77 119 w
0x38 56 8 0x58 88 X 0x78 120 x
0x39 57 9 0x59 89 Y 0x79 121 y
0x3A 58 : 0x5A 90 Z 0x7A 122 z
0x3B 59 ; 0x5B 91 [ 0x7B 123 {
0x3C 60 < 0x5C 92 \ 0x7C 124 |
0x3D 61 = 0x5D 93 ] 0x7D 125 }
0x3E 62 > 0x5E 94 ^ 0x7E 126 ~
0x3F 63 ? 0x5F 95 _ - - -

Types of characters in Character Set in C 

[Click Here for Sample Questions]

The characters in the C programming language can be distinctly divided into two categories-

  • Source character set- Source character set is the compilation of those characters in the C language which may be used in the C source code before the preprocessing phase. 
  • Execution character set- The set of characters which can store character string constants and can be interpreted by the running program is called the execution character set. It includes control characters, escape sequences and characters of the basic subset.
  • Basic character set- This character set includes common characters of both the source character set and an execution character set. 
  • Alphabets- The C language supports all 26 alphabets in both lowercase and uppercase forms. 

Uppercase alphabets ASCII Value
A 65
B 66
C 67
D 68
E 69
F 70
G 71
H 72
I 73
J 74
K 75
L 76
M 77
N 78
O 79
P 80
Q 81
R 82
S 83
T 84
U 85
V 86
W 87
X 88
Y 89
Z 90
Lowercase Alphabets ASCII Value
a 97
b 98
c 99
d 100
e 101
f 102
g 103
h 104
i 105
j 106
k 107
l 108
m 109
n 110
o 111
p 112
q 113
r 114
s 115
t 116
u 117
v 118
w 119
x 120
y 121
z 122
  • Digits- The 10 constituent digits of numerical values are included in the C programming language 

DIGITS ASCII value
0 48
1 49
2 50
3 51
4 52
5 53
6 54
7 55
8 56
9 57
  • Special Symbols- Symbols like brackets (,[,),] and ×,÷,=,*,& are often used to facilitate communication. There is a set of commonly used symbols in the C programming language as well.

Special Symbols  ASCII Value 
~ 126
! 33
@ 64
# 35
$ 36
% 37
& 38
* 42
( 40
) 41
39
34
< 60
\ 92
; 58
: 59
/ 47
? 63
> 62
45
_ 95
+ 43
= 61
{ 123
} 125
| 124
  • White Space- whitespace is any character or series of characters that represent horizontal or vertical space in typography in computer programming.

White Space Meaning
\0 null
\b blank space
\t horizontal tab
\v vertical tab
\’ single quote
\” double quote
\? Question mark
\a alarm (bell)
\r carriage return
\f form feed
\n new line
\\ back slash

Summary of all the Characters in C

[Click Here for Sample Questions]

Here is the summary in the tabulated form:

CONTROL CHARACTERS  ASCII Value Character
0 NULL Null
1 SOH Start of Header
2 STX Start of Text
3 ETX End of Text
4 EOT End of Transaction
5 ENQ Enquiry
6 ACK Acknowledgement
7 BEL Bell
8 BS Backspace
9 HT Horizontal Tab
10 LF Line Feed
11 VT Vertical Tab
12 FF Form Feed
13 CR Carriage Return
14 SO Shift Out
15 SI Shift In
16 DLE Data Link Escape
17 DC1 Device Control 1
18 DC2 Device Control 2
19 DC3 Device Control 3
20 DC4 Device Control 4
21 NAK Negative Acknowledgement
22 SYN Synchronous Idle
23 ETB End of Trans Block
24 CAN Cancel
25 EM End of Medium
26 SUB Substitute
27 ESC Escape
28 FS File Separator
29 GS Group Separator
30 RS Record Separator
31 US Unit Separator
33 ! -
34 -
35 # -
36 $ -
37 % -
38 & -
39 ' -
40 ( -
41 ) -
42 -
43 + -
44 , -
45 -
46 . -
47 / -
48 0 -
49 1 -
50 2 -
51 3 -
52 4 -
53 5 -
54 6 -
55 7 -
56 8 -
57 9 -
58 : -
59 ; -
60 < -
61 = -
62 > -
63 ? -
64 @ -
65 A -
66 B -
67 C -
68 D -
69 E -
70 F -
71 G -
72 H -
73 I -
74 J -
75 K -
76 L -
77 M -
78 N -
79 O -
80 P -
81 Q -
82 R -
83 S -
84 T -
85 U -
86 V -
87 W -
88 X -
89 Y -
90 Z -
91 [ -
92 | -
93 ] -
94 ^ -
95 _ -
96 - -
97 a -
98 b -
99 c -
100 d -
101 e -
102 f -
103 g -
104 h -
105 i -
106 j -
107 k -
108 l -
109 m -
110 n -
111 o -
112 p -
113 q -
114 r -
115 s -
116 t -
117 u -
118 v -
119 w -
120 x -
121 y -
122 z -
123 { -
124 | -
125 } -
126 - -
127 DEL -

Also Read:


Things to Remember 

  • C programming language is a general purpose programming language used to create software, databases and operating systems like windows etc.
  • It has a total of 256 characters.
  • It has different kinds of characters like printable, escape sequences, control characters etc.
  • Control characters are used to carry out any action, while printable characters are utilized to print characters on display. 
  • Printable characters include digits, special symbols, White spaces and all english alphabets in lowercase and uppercase.
  • Any character outside the character set is not supported by the program and shows invalid when entered.

Sample Questions

Ques. C programming language was developed by (1 mark)
a) Dennis Ritchie
b) Ken Thompson
c) Bill Gates
d) Peter Norton

Ans: (a)

Explanation: The American Computer scientist Dennis Ritchie designed the C programming language which gained great significance in the latter years. 

Ques. C was developed in the year ___ (1 mark)
a) 1970
b) 1972
c) 1976
d) 1980

Ans: (b)

Dennis Ritchie developed the C programming language at Bell Labs of AT&T (American Telephone and Telegraph) located in the U.S. in 1972.

Ques. Which of the following are tokens in C? (1 mark)
a) Keywords
b) Variables
c) Constants
d) All of the above

Ans: (d)

Explanation: Tokens are the smallest building units of a C program. Each and every word, mark or punctuation you come across in a C program is a token. Therefore Keywords variables, constants, and identifiers are all tokens.

Ques. The maximum length of a variable in C is ___ (1 mark)
a) 8
b) 16
c) 32
d) 64

Ans: (a)

Explanation: The maximum integral value which you can fit in a variable is 8 bytes. Therefore the Ans will be 

Ques. Which of the following options is correct if one wants to exchange the values of x and y variables? (1 mark)
(a) We need to call Swap(x,y)
(b) we need to call swap(&x,&y)
(c) We can not call swap (x,y) because it does not return any value
(d) We can not call swap (x,y) because parameters are passed by value

Ans : (d)

Explanation: Option a, b and c are incorrect because of the following reason.

(a) We need to call Swap(x,y)

(b) we need to call call swap(&x,&y)

(c) We can not call swap (x,y) because it does not return any value

In order to exchange the value of x and y we should call swap(&x, & y) but for it’s working at the time of function definition we should pass parameter as a pointer it means we should define void swap( int *x, int*y)

So function call Swap(x,y) can not not be used because the parameter is passed as a value instead of pointer types arguments.

Ques. What does the following C statement declare? [GATE 2005] (1 mark)
int (*f)(int *);
(a) A function that takes an integer pointer as an argument and returns an integer.
(b) A function that takes an integer as an argument and returns an integer pointer.
(c) A pointer to a function that takes an integer pointer as an argument and returns an integer.
(d) A function that takes an integer pointer as an argument and returns a function pointer.

Ans: Option C is correct Ans because int(*f)(int *); is a statement which represents a pointer to a function that takes an integer argument and returns an integer.

Ques. What does the following fragment of C-program print? [GATE 2011] (1 mark)
char c[ ] = “GATE2011”;
char *p = c;
printf(“%s”, p + p[3] – p[1]);
(a) GATE 2011
(b) E2011
(c) 2011
(d) 01

Ans: C

Solution: char c[ ] = “GATE2011”;

since char *p =c it means p represents to the base address of string “2011”

SO p[3] is ‘E’ and p[1] is ‘A’.

Value of Sub expression p[3] – p[1] = ASCII value of ‘E’ – ASCII value of ‘A’ = 4

// So the expression p + p[3] – p[1] becomes ( p + 4) which is

And (p+4) represent to base address of string “2011”

printf(“%s”, p + p[3] – p[1]);

So it will print 2011

Ques. The output of the following C program is_____ [ GATE 2015]. (3 marks)
void f1(int a, int b)
{
int c;
c=a; a=b; b=c;
}
void f2(int *a, int *b)
{
int c;
c=*a; *a=*b; *b=c;
}
int main(){
int a=4, b=5, c=6;
f1(a,b);
f2(&b, &c);
printf(“%d”,c-a-b);
}

Ans. -5

Explanation: The first function call f1(a,b) has no effect because here the parameters are passed as call by value. So function signatures don’t match.

Second function call f2(&b,&c) signature matched. So it will work correctly . So value of variable b and c will be swapped and new value of b will be 6 and c will be 5 so c-a-b will be = 5-6-4= -5

Ques. Consider the following C program [ GATE 2018] (3 marks)
#include< stdio.h >
void fun1(char *s1, char *s2){
char *tmp;
tmp = s1;
s1 = s2;
s2 = tmp;
}
void fun2(char **s1, char **s2){
char *tmp;
tmp = *s1;
*s1 = *s2;
*s2 = tmp;
}
int main(){
char *str1 = “Hi”, *str2 = “Bye”;
fun1(str1, str2); printf(“%s %s “, str1, str2);
fun2(&str1, &str2); printf(“%s %s”, str1, str2);
return 0;
}
The output of the program above is

Ans. fun1(char *s1, char *s2)

This function has a local scope therefore the value changed here won’t affect actual parameters and values will be ‘Hi Bye’.

 Let’s understand second function

fun2(char **s1, char **s2)

Since here in this function value is pointer to pointer, it will change the pointer of the actual value. In this case values will be ‘Bye Hi’

So the Ans is ‘Hi Bye Bye Hi’

Ques. Consider the following C program: GATE [2019] (3 marks)
#include < stdio.h >
int main()
{
int a[] = {2, 4, 6, 8, 10} ;
int i, sum = 0, *b = a + 4 ;
for (i = 0; i < 5; i++)
sum = sum + (*b – i) – *(b – i) ;
printf (“%d\n”, sum) ;
return 0 ;
}
The output of the above C program is _____.

Ans. 10

Explanation: In the above program the loop will be run from i=0 to i=4.

When i=0 then

Sum= 0+10-0 =0

When i= 1 then

Sum = 0+9-8

Sum=1

When i=2 then

Sum=1+8-6=3

When i=3 then

Sum=3+7-4=6

When i =4 then

Sum= 6+ 6-2=10

So output will be 10.

For Latest Updates on Upcoming Board Exams, Click Here: https://t.me/class_10_12_board_updates


Check-Out: 

Comments


No Comments To Show