num and initialize it with a value.printf() function to display the value.In C programming, a token is the smallest individual unit of a program that has a meaningful interpretation to the compiler. Tokens are the building blocks of a C program. The major types of tokens in C are:
#include <stdio.h>
int main()
{
int num = 100;
printf("Value of num = %d", num);
return 0;
}
Value of num = 100
Let's identify the tokens used in the above program:
| Token Type | Example | Description |
|---|---|---|
| Keyword | int, return | Reserved words with predefined meanings in C. |
| Identifier | main, num, printf | Names given to variables, functions, and other user-defined entities. |
| Constant | 100 | A fixed value that does not change during program execution. |
| Operator | = | Used to perform operations on variables and values. |
| Special Symbols | { }, ( ), ; | Symbols that help define the structure of a C program. |
In this program, the statement int num = 100; contains multiple tokens. Here, int is a keyword, num is an identifier, = is an operator, 100 is a constant, and ; is a special symbol. Together, these tokens form a valid C statement that the compiler can understand and execute.
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.