Tokens in C

A C program is built using smallest individual units called tokens. Just like a sentence is made from words, a C program is made from tokens. Understanding tokens is essential because every piece of C code is written using one or more of these token types.

What Are Tokens?

Tokens are the smallest elements of a C program that have a meaning to the compiler. They cannot be broken further. All valid C statements are formed using these tokens.

Types of Tokens in C

There are 6 main types of tokens in C:

1. Keywords  
2. Identifiers  
3. Constants  
4. Strings  
5. Operators  
6. Special Symbols  
Below, each token is explained with simple examples.

1. Keywords

These are reserved words that have a fixed meaning in C. They cannot be used as variable names.

int age;

Here, int is a keyword.

2. Identifiers

Identifiers are names given to variables, functions, arrays, etc.

int marks;
float totalScore;

Here, marks and totalScore are identifiers.

3. Constants

Constants are fixed values that do not change during program execution.

const int MAX = 100;

4. String Literals

Strings are sequences of characters written inside double quotes.

"Hello World"
"Welcome to C Programming"

They end with a hidden null character ('\0').

5. Operators

Operators perform operations on operands (variables, values).

Common operator groups:

Operators + Operands = Expression Example: a + b

6. Special Symbols

Symbols that have a special meaning in C.

printf("Hello");

Here, () and ; are special symbols.

Diagram: Tokens at a Glance

        TOKEN TYPES IN C
        -------------------
        | Keywords        |
        | Identifiers     |
        | Constants       |
        | Strings         |
        | Operators       |
        | Special Symbols |
        -------------------

Practice Questions

  1. What are tokens in C? Explain.
  2. Differentiate between keywords and identifiers.
  3. Write examples of all types of constants.
  4. Explain operators with examples.
  5. List any five special symbols used in C.

Practice Task

Write a C program and highlight all tokens used in it (keywords, identifiers, constants, operators, special symbols).
#include <stdio.h>

int main() {
    int a = 10, b = 20;
    printf("Sum = %d", a + b);
    return 0;
}