Session 2 - C Character Set and C Tokens
Session 2 - C Character Set and C Tokens
2.1 Introduction
2.4 C Tokens
2.5 Summary
2.1 Introduction
Welcome to this session. The programming language that we shall use in this
course is C language. We shall start by looking at the set of characters used
in C language and the basic building block of C language commonly known
as C tokens.
1
characters used in that language. For example, when we start learning
English, firstly we require to learn English alphabets.
Similarly, there are many characters that can be used to write a C program.
The collection of those characters is referred as "C Character Set".
2.3 C Tokens
i. Keywords
ii. Identifiers
2
iii. Literals (or Constants)
iv. Operators
v. Separators (or Punctuators)
i. Keywords
Keywords are a set of reserved words that have a specific or special meaning
to C language. These words are called reserve words because they are reserve
for C program. There are total 32 keywords in C. They are always written in
small case alphabets. They are:
double
ii. Identifiers
3
Naming Rules for Identifiers:
In real life, we can name our pet, our house or anything that we want to name
and there may be no specific rule for naming. Although, we take care that the
name we choose do not hurt the sentiments of some other person. Some other
names might be meaningful also. But in C there are some rules that need to
be followed for naming identifiers. When naming identifiers, the following
rules must be followed:
3. It can be up-to 8 characters long (in DOS) and 256 characters long (in
Windows).
6. It’s case sensitive: small case and capital case alphabets are distinct.
Example:
4
iii. Literals (or Constants)
These are constant values that can be used in a C program. Constants are
fixed values that the program may not alter during its execution.
iv. Operators
A + B, A+10 etc.
5
Types of operators in C
a. Arithmetic operators
b. Assignment operator
d. Logical operators
f. Conditional operators
g. Bit-wise operators
Arithmetic Operators
v. Modulus ( % )
This operator is used to find the remainder. Both of its operands must be
integer.
6
Example 1: 10%3 = 1
Example in Mathematics:
A = B + 20 (Correct)
B + 20 = A (Correct)
Example in C language:
A = B + 20 (Correct)
B + 20 = A (Incorrect)
Example:
A+ = 10 It means A = A + 10
A* = B It means A = A * B
and so on…
These are symbols used to separate a group of code from one another. The
most commonly used separator is a semicolon. Semicolon is used to terminate
the statement. Various separators in C are:
7
a. [ ] – Brackets
b. ( ) – Parentheses
c. { } – Braces
d. ; - Semi Colon
e. . - Period (Dot)
f. , - Comma
#include <stdio.h>
int main()
{
int number1, number2, sum;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
// calculating sum
sum = number1 + number2;
Literals (Constants): "Enter two integers: " "%d %d" "%d + %d = %d" 0
Operators: & = +
Separators: () {} , ;
2.5 Summary
In this session, we have learnt about the set of characters used in C language.
We have also looked at C Tokens which are: keywords, identifiers, operators,
literals and separators. We also looked at various types of operators and
discussed in depth about arithmetic operators.