2. Character Sets
A character refers to the digit, alphabet or special symbol used to data representation.
1. Alphabets : A-Z, a-z
2. Digits : 0-9
3. Special Characters: ~! @ # $ % ^ & * ( ) _ + { } [ ] - <> , . / ? | : ; " '
4. White Spaces : Horizontal tab, Carriage return, New line, form feed
T A R U N S H A R M A 2
3. Token’s
C tokens are the basic buildings blocks in C language which are constructed together to write a C
program. Each and every smallest individual unit in a C program is known as C tokens. C has five
types of tokens:
1. Keywords
2. Identifiers
3. Constants
4. Separators
5. Operators
T A R U N S H A R M A 3
4. For Example:
main – identifier
{,}, (,) – separator
int – keyword
x, y, total – identifier
main, {, }, (, ), int, x, y, total – tokens
T A R U N S H A R M A 4
5. Keywords
All keywords have fixed meaning & there meanings cannot be changed during the execution of a
program. Keywords served as basic building block for program statements. White spaces are not
allowed in keywords. Keywords may not be used as an identifier. ‘C’ has 32 keywords, all
keywords written in lower case. For example, if, int, for, float, while etc.
T A R U N S H A R M A 5
6. Identifier
Identifier refers to the name of variable, functions and array. These are user define names &
consist of a sequence of letter & digits both uppercase and lowercase letters are permitted.
Rule of identifier:
1. First character must be an alphabet and underscore.
2. Must consist of only letters, digits and underscore.
3. Cannot use a keyword.
4. Must not contain white space.
For example:
int price;
int tv_price;
Here, price & tv_price; is a identifier which denotes a variable of type integer.
T A R U N S H A R M A 6
7. Separators
Separators are used to separate a program statement in a program. For example, comma “,”,
parenthesis “( )”, curly braces “{ }”, square braces “[ ]”.
T A R U N S H A R M A 7
8. Constants
Constant in ‘C’ refers to fixed value & do not change during the execution of a program. ‘C’
supports several types of constant.
1. Integer Constants
2. Real Constants / Floating Point Constants
3. Character Constants
4. String Constants
T A R U N S H A R M A 8
9. Integer Constants
Integer constants are whole numbers without any fractional part. Thus integer constants consist
of a sequence of digits. Integer constants can be written in three different number systems:
Decimal, Octal and Hexadecimal.
A decimal integer constant consists of any combination of digits taken from the set 0 through 9.
The octal constant starts from 0 like “013”. And the hexadecimal constant starts from “0x” like
“0x16”.
Example: “145”, “12223”, “-1234”.
T A R U N S H A R M A 9
10. Real Constants
A floating-point constant is a base-10 number that contains either a decimal point or an
exponent or both.
The floating point must have a decimal point which may be positive or negative. Use of blank
space and comma is not allowed between floating/ real constants.
Example: “+194.143”, “-416.41”.
T A R U N S H A R M A 10
11. Character Constants
Every number, symbol or a digit in a single quotes called character constants. Character
constants are of two types:
Single Character Constants
A character constant is a single character, enclosed in single quotation marks. e.g., ‘A’ ‘B’ ‘1’.
Characters are stored internally in computer as coded set of binary digits, which have positive
decimal integer equivalents. The value of a character constant is the numeric value of the
character in the machine’s character set.
For example, on ASCII machine the value of ‘A’ is 65.
T A R U N S H A R M A 11
12. Character Constants Continue..
Non Graphical Character / Escape Sequence Character Constants:
C supports some special escape sequence characters that are used to do special tasks. These are
also called as 'Backslash characters'. Some of the escape sequence characters are as follow:
T A R U N S H A R M A 12
13. Character Constants Continue..
String Constant
It is collection of characters enclosed in double quotes. It may contain letters, digits, special
characters and blank space. Example:
“Hello World!"
T A R U N S H A R M A 13
14. Operators
The symbols which are used to perform logical and mathematical operations in a C program are
called C operators. C supports a rich set of built in operators. We have already used several of
them, such as +, -, *, /, %. Operators are used to perform a program to manipulate data &
variables. Operators are classified into a number of categories:
1. Arithmetic Operators
2. Relational Operator
3. Logical Operator
4. Assignment Operator
5. Increment & Decrement Operator
6. Conditional Operator
7. Bitwise Operator
8. Special Operator (Sizeof())
T A R U N S H A R M A 14
15. Arithmetic Operator
C Arithmetic operators are used to perform mathematical calculations like addition, subtraction,
multiplication, division and modulus in C programs.
Example: “c=a+b;”
T A R U N S H A R M A 15
16. Relational Operator
Relational operators are used to find the relation between two variables i.e. to compare the
values of two variables in a C program. For example, we may compare the age of 2 persons, or
the price of 2 items and so on.
Example: “age>=60;”
T A R U N S H A R M A 16
17. Logical Operator
These operators are used to perform logical operations on the given expressions. There are 3
logical operators in C language. They are, logical AND (&&), logical OR (||) and logical NOT (!). It
returns Boolean values (0,1). Truth Table:
Example: “a==b && a%2==0”
T A R U N S H A R M A 17
18. Assignment Operator
In C programs, values for the variables are assigned using assignment operators. For example, if
the value “10″ is to be assigned for the variable “sum”, it can be assigned as “sum = 10;”. Other
assignment operators in C language are given below.
T A R U N S H A R M A 18
19. Bitwise Operator
These operators are used to perform bit operations. Decimal values are converted into binary
values which are the sequence of bits and bit wise operators work on these bits. Bit wise
operators in C language are & (bitwise AND), | (bitwise OR), ^ (XOR), << (left shift) and >> (right
shift).
T A R U N S H A R M A 19
21. Bitwise Operator Continue.
Bitwise AND (&) Operator
The output of Bitwise AND is 1 if both the corresponding bits of operand is 1. If either of bit is 0
or both bits are 0, the output will be 0.
T A R U N S H A R M A 21
22. Bitwise Operator Continue.
Bitwise OR (|) Operator:
The output of bitwise OR is 1 if either of the bit is 1 or both the bits are 1. In C Programming,
bitwise OR operator is denoted by |.
T A R U N S H A R M A 22
23. Bitwise Operator Continue.
Bitwise XOR (Exclusive OR) Operator
The output of bitwise XOR operator is 1 if the corresponding bits of two operators are opposite
(i.e., To get corresponding output bit 1; if corresponding bit of first operand is 0 then,
corresponding bit of second operand should be 1 and vice-versa.). It is denoted by ^.
T A R U N S H A R M A 23
24. Bitwise Operator Continue.
Bitwise Left Shift Operator
Left shift operator moves the all bits towards the left by certain number of bits which can be
specified. It is denoted by <<.
T A R U N S H A R M A 24
25. Bitwise Operator Continue.
Bitwise Right Shift Operator
Right shift operator moves the all bits towards the right by certain number of bits which can be
specified. It is denoted by >>.
T A R U N S H A R M A 25
26. Conditional / Ternary Operator
Conditional operators return one value if condition is true and returns another value is condition
is false. This operator is also called as ternary operator.
Syntax : (Condition? true_value: false_value);
Example: (A > 100? 0: 1);
In above example, if A is greater than 100, 0 is returned else 1 is returned.
T A R U N S H A R M A 26
27. Increment / Decrement Operator
Increment operators are used to increase the value of the variable by one and decrement
operators are used to decrease the value of the variable by one in C programs.
Syntax:
Increment operator : ++var_name; (or) var_name++;
Decrement operator : -- var_name; (or) var_name --;
Example:
Increment operator: ++ i; i ++;
Decrement operator: --i; i--;
T A R U N S H A R M A 27
28. Increment / Decrement Operator Cont.
Difference between ++ and -- operator as postfix and prefix:
When ++ is used as prefix (like: ++var), ++var will increment the value of var and then return it
but, if ++ is used as postfix (like: var++), operator will return the value of operand first and then
only increment it.
Example:
a=10;
b=a++; a=11 b=10
B=++a; a=11 b=11
T A R U N S H A R M A 28