Home C Programming Language / Programs / Demonstration of Tokens in C Language
🚀 Programming Example

Demonstration of Tokens in C Language

👁 4 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.
No previous program
No next program

📌 Information & Algorithm

  1. Start the program.
  2. Declare an integer variable num and initialize it with a value.
  3. Use the printf() function to display the value.
  4. Observe the different tokens used in the program such as keywords, identifiers, constants, operators, and special symbols.
  5. End the program.

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:

  • Keywords (e.g., int, return)
  • Identifiers (e.g., main, num)
  • Constants (e.g., 100)
  • Operators (e.g., =)
  • Special Symbols (e.g., { }, ( ), ;)

💻 Program Code

#include <stdio.h>

int main()
{
    int num = 100;

    printf("Value of num = %d", num);

    return 0;
}
                        

🖥 Program Output

Value of num = 100
                            

📘 Explanation

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.

No previous program
No next program
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

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.

🔥 Practice suggestion

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.