Tokens in C language
A token is the smallest element of a program that is meaningful to the compiler. The compiler breaks a program into the smallest possible units (tokens) and proceeds to the various stages of the compilation.
Tokens in C are divided into six different types.
- Keywords
- Identifiers
- Constants
- Strings
- Special Characters
- Operators
Keywords
Keywords are pre-defined or reserved words in a programming language and has a special meaning to compiler to perform a specific function in a program. These can’t be used as variable names as it means we are assigning a new meaning to the keyword which is not allowed.
C language supports 32 keywords which are 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
An identifier represent the name in the C program and used for naming variables, functions, structures, unions, labels, etc. An identifier can be composed of letters such as uppercase, lowercase letters, underscore, digits, but the starting letter should be either an alphabet or an underscore.
Rules for constructing identifier:
- They must begin with a letter or underscore(
_
). - They must consist of only letters, digits, or underscore. No other special character is allowed.
- It should not be a keyword.
- It must not contain white space.
- It should be up to 31 characters long as only first 31 characters are significant.
- Identifiers should be written in such a way that it is meaningful, short, and easy to read.
Example: total
, sum
, name
, _define
etc