C Tokens
In C programming, the smallest individual units of a program are known as tokens. Tokens are the basic building blocks of a C program.
Types of C Tokens
C tokens are classified into six types:
- Keywords
- Identifiers
- Constants
- Strings
- Operators
- Special Symbols
1. Keywords
Keywords are reserved words in C that have special meanings. They cannot be used as variable names. Examples of keywords include:
int, float, char, return, if, else, while, for, switch, break
2. Identifiers
Identifiers are the names used for variables, functions, arrays, etc. They must begin with a letter or an underscore (_) and can be followed by letters, digits, or underscores.
3. Constants
Constants are fixed values that do not change during program execution. They can be:
- Integer Constants: e.g.,
10, -50, 1000
- Floating-point Constants: e.g.,
3.14, -0.001, 2.5e3
- Character Constants: e.g.,
'A', '5', '*'
4. Strings
Strings in C are sequences of characters enclosed in double quotes (" "
). Example:
"Hello, World!", "C programming"
5. Operators
Operators are symbols that perform operations on variables and values. Some examples include:
- Arithmetic Operators:
+, -, *, /, %
- Relational Operators:
==, !=, >, <,>=, <=
- Logical Operators:
&& (AND), || (OR), ! (NOT)
6. Special Symbols
These include symbols such as brackets, commas, semicolons, etc., used for syntax structuring. Example:
;
(Semicolon - statement terminator){ }
(Curly braces - block of code)( )
(Parentheses - function parameters)
Example Program
Below is a simple program demonstrating the use of various tokens:
#include <stdio.h>
int main() {
int num = 10; // Identifier and integer constant
float pi = 3.14; // Floating-point constant
char letter = 'A'; // Character constant
printf("Number: %d\n", num);
printf("Pi: %.2f\n", pi);
printf("Letter: %c\n", letter);
return 0;
}
Explanation
int, float, char
- Keywords.num, pi, letter
- Identifiers.10, 3.14, 'A'
- Constants.printf()
- Function for displaying output.
If you have any questions, feel free to ask. Thank you for reading!
If you have any query or question, please contact through below form. Our team will be in touch with you soon.
Please provide your valueable feedback or suggession as well.