In this tutorial, we will learn about C tokens and types of tokens in C. Tokens are the smallest individual unit or building block of a program that conveys special meaning to the language compiler. C Token is also known as Lexical Units.
C Token Diagram
![]() |
C Token Diagram |
Types of C Token are
- Keywords
- Identifiers
- Constants
- Operators
- Strings
- Special Symbols
Keywords in C
Keywords are reserved words having a special meaning in the programming language. These Keywords in c are pre-defined words in a programming language that convey a special meaning to the compiler.
C language supports 32 keywords. C keywords classification which is given below
Identifiers in C
The identifier is a fundamental building block and is used as the general terminology for names given to different parts of programs are variables, arrays, and functions.
Rules for naming identifiers
- The first character must be Letter(A-Z or a-z) or Underscore(_).
- You can not use any special symbol in identifier i.e. @,+,-,., etc.
- You can not use keywords as identifiers.
- It should not contain any space between them.
- In the same program, two or more same identifiers are not possible.
Some examples of identifiers in c are
_file Valid
MY.DOB invalid because it contains a special symbol dot(.)
Constants in C
Constants refer to fixed values. Constants in c like any other normal variables of the program but the only difference is once you defined than their data items( values ) that never change or modify their value during execution of a program. These are also known as Literals.
Following are the various types of constants c token
- Integer Constants
- Character Constants
- Floating Constants
- String constants
Operators in C token
Operators are that are trigger some calculus when applied to variables in an expression. Operators are acts on operands (Operands are data items on which operators act.)
C token Operators are classified on the basis of the number of operands are
- Unary Operators: These are operators those required one operand to operates.
++ increment
-- decrement, etc.
- Binary Operators: These are operators that required two operands to operates on it.
Some Binary Operators are followed:
- Arithmetic operators
- Assignment Operators
- Bitwise Operators
- Conditional Operators
- Logical Operators
- Relational Operator
Strings in C token
A string in c token is a character array that ended with a null character (‘\0’). Null character shows the end of the character array. Strings are always enclosed in double quotes(“”) and character is enclosed by single quotes(‘’).
Examples
Examples
char string[20] = “codeamy”; \\ In this 20 bytes of memory space is allocated by programmers to holding the string.
(or)
char string [] = “codeamy”; \\ In this memory space is allocated by the compiler at the time of execution.
(or)
char string[20] = {‘c’, ’o’, ‘d’, ‘e’, ‘a’, ‘m’, ‘y’, ‘\0’};
(or)
char string [] = “codeamy”; \\ In this memory space is allocated by the compiler at the time of execution.
(or)
char string[20] = {‘c’, ’o’, ‘d’, ‘e’, ‘a’, ‘m’, ‘y’, ‘\0’};
Special Symbols in C Token
C token has special symbols used that have special meanings that cannot be used for another purpose.
- Asterisk (*)
- Assignment operator
- Curly Braces { }
- Comma (,)
- Parentheses ( )
- Preprocessor (#)
- Square Brackets [ ]
- Semicolon (;)