In C programming, a token is the smallest unit of a program. Tokens are the building blocks of a C program. A C program is made up of various types of tokens. These include:
Keywords are predefined, reserved words in C that have special meaning. These words cannot be used as identifiers (names of variables, functions, etc.). Examples of keywords include:
int, float, double, char, if, else, while, return, for, break, continue, switch
Identifiers are the names used to identify variables, functions, arrays, or any other user-defined item. The rules for naming identifiers are:
age
and Age
are different).Constants are fixed values that do not change during the execution of the program. In C, constants can be of various types:
10
, 100
.3.14
, 2.718
.'A'
, 'b'
.String literals are a sequence of characters enclosed in double quotes. For example:
"Hello, World!" "Welcome to C programming!"
Operators in C are symbols that perform operations on variables and values. There are different types of operators in C, including:
+, -, *, /, %
==, !=, >, <, >=, <=
&&, ||, !
=
Separators are symbols that separate statements and parts of the program. The common separators are:
Hereβs an example program with various tokens:
#include// Header File int main() { // Function Start int num = 5; // Keyword, Identifier, Constant printf("Value: %d", num); // Keyword, Identifier, String Literal, Operator return 0; // Keyword, Operator }
int a = 10; char b = 'A'; float result = a * 2.5; printf("Result: %f", result);
int
as a variable name).Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!