Token Types
1 minute read
Token Types
What is Token
Tokens are the smallest word of a program, which are meaningful for the compiler.
Six types of tokens in C Language. They are
1. Keywords (eg: int, while),
2. Identifiers (eg: main, total),
3. Constants (eg: 10, 20),
4. Strings (eg: “total”, “hello”),
5. Character set (eg: A-Z,a-z),
6. Operators (eg: +, /,-,*)
Keywords
Keywords are reserved words in C and each keyword has specific meaning.
There are total 32 keywords in C.
Auto | Double | int | struct |
Break | Else | long | switch |
Case | Enum | register | typedef |
Char | Extern | return | union |
Continue | For | signed | void |
Do | If | static | while |
Default | Goto | sizeof | volatile |
Const | Float | short | unsigned |
Identifier
Every program's element is known as an identifier. They are used for naming of variables, functions, array etc. Identifier are user-defined names which consist of number,alphabets, underscore ‘_’. Identifier’s name should not be same as keywords. Keywords are not used as identifiers.
Rules for naming C identifiers −
· It must begin with alphabets or underscore.
· Only numbers, alphabets, underscore can be used, no other special characters, punctuations are allowed.
· It must not contain white-space.
· It should not be a keyword.
· It should be up to 31 characters.
Strings
A string is a collection of characters. This null character indicates that string has ended. Strings are always enclosed with double quotes(“ “).
Example
char string[20] = “demo”;
Here last character of string is '\0'.
Here last character of string is '\0'.
Character set
A character set in 'C' is divided into,
- Letters
- Numbers
- Special characters
- White spaces (blank spaces)
Following is the character set in 'C' programming:
1. Letters
o Uppercase characters (A-Z)
o Lowercase characters (a-z)
2. Numbers
o All the digits from 0 to 9
3. White spaces
o Blank space
o New line
o Carriage return
o Horizontal tab
4 Special character
o !@#$%^&*