In C language the smallest unit of a program is called Token. It is the most important element to be used in creating a program in C. Tokens in C is the building block or the basic component for creating a program in C language.
Classification of tokens in C
Tokens in C language can be divided into the following categories:
Let's understand each token one by one.
Keywords in C can be defined as the pre-defined or the reserved words that are already defined within the C language and cannot be changed. Since keywords are the pre-defined words used by the compiler, so they cannot be used as the variable names. C language supports 32 keywords given below.
auto | double | int | struct |
break | else | long | switch |
case | enum | register | typedef |
char | extern | return | union |
const | float | short | unsigned |
continue | for | signed | void |
default | goto | sizeof | volatile |
do | if | static | while |
Identifiers are user-defined words used for naming variables, functions, arrays, structures, etc. An Identifiers consists of uppercase letters, lowercase letters, underscore, or digits, but the starting letter should be either an underscore or an alphabet. Identifiers cannot be used as keywords.
Rules for constructing identifiers in C are given below
Strings in C are always represented as an array of characters having null character '\0' at the end of the string. This null character denotes the end of the string. Strings are enclosed within double quotes, while characters are enclosed within single characters. The size of a string is a number of characters that the string contains.
In the below exaple strings are represented in different ways:
char a[10] = "rookienerd"; // The compiler allocates the 10 bytes to the 'a' array.
char a[] = "rookienerd"; // The compiler allocates the memory at the run time.
char a[10] = {'r','o','o','k','i','e','n','e','r','d','\0'}; // String is represented in the form of characters.
Operators in C is a symbol that tells the compiler to perform a certain mathematical or logical manipulation. Operators are used in programs to manipulate the data and variables. C language supports a rich set of built in operators.
The data items on which the operators are applied are known as operands. Operators are applied between the operands. Depending on the number of operands, operators are classified as follows.
A unary operator is an operator applied to the single operand. For example: increment operator (++), decrement operator (--), sizeof, (type)*.
The binary operator is an operator applied between two operands. The following is the list of the binary operators:
Constants are those tokens in C language whose value is fixed and does not change during the execution of a program.
There are two ways of declaring constant:
Types of constants in C
Constant | Example |
Integer constant | 10, 11, 34, etc. |
Floating-point constant | 45.6, 67.8, 11.2, etc. |
Octal constant | 011, 088, 022, etc. |
Hexadecimal constant | 0x1a, 0x4b, 0x6b, etc. |
Character constant | 'a', 'b', 'c', etc. |
String constant | "java", "c++", ".net", etc. |
Some special characters are used in C, and they have a special meaning which cannot be used for another purpose.