Lecture-2.2-C Token
Lecture-2.2-C Token
C tokens
C tokens are the basic buildings blocks in C language which are
constructed together to write a C program.
Each and every smallest individual units in a C program is known
as C token or a lexical unit.
C tokens can be classified in six types as follows:
① Keywords (e.g., int, while, do …),
② Identifiers (e.g., main, total, my_var …),
③ Constants (e.g., 10, 20 , - 25.5 … ),
④ Strings (e.g., “total”, “hello” , “DIU” …),
⑤ Special symbols (e.g., (), {} , [] …),
⑥ Operators (e.g., +, /, - , * …)
C tokens
C tokens example program
where,
Main, x, y, total – identifier
{,}, (,) – special symbols
int , return – keyword
10, 20 – constant
=,+ – operator
“Total 30” – String
main, {, }, (, ), int, x, y, total etc– all these are various
tokens
C Keywords
There are some reserved words in C language whose meaning are predefined
in C compiler, those are called C keywords.
Each keyword is meant to perform a specific function in a C program.
Each keywords has fixed meaning and that cannot be changed by user.
Since upper case and lowercase characters are not considered same in C, we
can use an uppercase keyword as an identifier. But it is not considered as
good programming practice.
Keywords
There are 32 keywords in C which are given below. keywords are all lowercase.
Identifiers
Each program elements in a C program are given a name called identifiers.
Names given to identify variables, functions etc. are examples for identifiers.
e.g., int x ; here x is a name given to an integer variable.
For example:
Decimal constants: 0, -9 , 22 etc
Octal constants: 021, 077, 033 etc
Hexadecimal constants: 0x7f, 0x2a, 0x521 etc
Real constant, also called Floating point constants are the numeric constants
that has either fractional form or exponent form.
For example:
-2.0
0.0000234
-0.22E-5
Single character constants are the constant which use single quotation around
characters.
For example: 'a', 'l', 'm', 'F' etc.
All character constants have an equivalent integer value which are called
ASCII Values.
String constants
Depending on the number of operands that an operator can act upon, operators can be
classified as follows:
Unary Operators: Those operators that require only single operand to act upon are known
as unary operators.
Binary Operators: Those operators that require two operands to act upon are called
binary operators.
Ternary Operators: These operators requires three operands to act upon.
The multiple-character operators can not have white spaces or comments between the
characters.