Lesson Progress
0%
Lesson  ·  Tokens in C

Tokens — The Words Inside Your Code

A sentence is made of words. A C program is made of tokens — the smallest pieces the compiler can actually recognize. Once you can spot the 5 token types in any line of code, reading unfamiliar C gets a lot less intimidating.

Keywords
Identifiers
Constants
Operators
Punctuators
📖

What Is a Token?

Take the sentence "The cat sat on the mat." — you instinctively read it as 6 separate words, not one long blob of letters. A token is that same idea applied to C code: the smallest unit that still means something on its own. The compiler doesn't read your code letter by letter either — it breaks it into tokens first, exactly like you break a sentence into words before understanding it.

📝
Real-world analogy: Reading a recipe. "Add two cups of flour" isn't one instruction — it's separate meaningful pieces: an action ("Add"), a quantity ("two cups"), and an ingredient ("flour"). C code breaks down the exact same way, just with 5 specific categories instead of grammar rules.

Every single line of C code is built from exactly 5 kinds of tokens:

  • Keywords — reserved words with a fixed meaning (int, if, return)
  • Identifiers — names you invent (variables, functions)
  • Constants / Literals — fixed values written directly (25, 'A', "Hi")
  • Operators — symbols that perform an action (+, =, >)
  • Punctuators / Special symbols — structural glue (;, { }, ( ), ,)
type 1
1

Keywords — Reserved Words You Can't Rename

🅿️
Real-world analogy: A "Reserved Parking" sign. That spot has one fixed purpose — you can't repaint the sign and use it for something else. C's 32 keywords work the same way: int, if, while, and return already have a fixed job in the language, so you can't use them as variable names.
keywords_demo.c
keywords_demo.c
C
int main() {
    int age = 20;

    if (age >= 18) {
        return 1;
    }
    return 0;
}

// int, if, return are KEYWORDS — fixed meaning, cannot be renamed
// This will NOT compile:
//    int if = 5;   // "if" is reserved, illegal as a variable name
CategoryExamples
Data typesint, float, char, double, void
Control flowif, else, switch, case, for, while, do
Jump statementsbreak, continue, return, goto
Storage/modifiersconst, static, extern, unsigned, signed
type 2
2

Identifiers — Names You Choose

🏷️
Real-world analogy: Naming a pet. Nobody assigns your dog's name for you — you pick something meaningful, following a few basic rules (no starting with a number, no spaces). Variable and function names in C work the same way — totalPrice, studentCount, calculateArea are all identifiers you invented.
identifiers_demo.c
identifiers_demo.c
C
int calculateArea(int length, int width) {
    int totalArea = length * width;
    return totalArea;
}

// calculateArea, length, width, totalArea are all IDENTIFIERS
// Rules: letters, digits, underscore only — can't start with a digit
// 2total   -> ILLEGAL (starts with a digit)
// total_2  -> LEGAL
// int      -> ILLEGAL as an identifier (it's a keyword!)
💡 Keywords vs identifiers, side by side: a keyword is a name C already gave meaning to; an identifier is a name you give meaning to. That's the entire distinction.
type 3
3

Constants / Literals — Fixed Values

🏷️
Real-world analogy: A price tag on a store shelf. The tag says ₹299 — fixed, printed, not changing based on context. Any value written directly into your code — a number, a single character, a piece of text — is a constant/literal for the exact same reason: it's fixed at that exact spot in the code.
constants_demo.c
constants_demo.c
C
int age = 25;              // 25         -> integer constant
float price = 99.50;      // 99.50      -> floating constant
char grade = 'A';        // 'A'        -> character constant
char name[] = "Ravi";    // "Ravi"     -> string literal
Constant typeExample
Integer constant25, -10, 0
Floating constant99.50, 3.14
Character constant'A', '7', '\n'
String literal"Ravi", "Hello"
type 4
4

Operators — Symbols That Do Work

Real-world analogy: The action words in a recipe — "add," "mix," "compare." +, =, and > aren't just symbols sitting there; each one tells the compiler to actually do something — add two numbers, store a value, or compare two things.
operators_demo.c
operators_demo.c
C
int a = 10, b = 3;

int sum = a + b;      // +  -> arithmetic operator
int isBigger = a > b; // >  -> relational operator
int result = (a > b) && (b > 0);  // && -> logical operator
CategoryExamples
Arithmetic+ - * / %
Relational> < >= <= == !=
Logical&& || !
Assignment= += -= *= /=
type 5
5

Punctuators — The Structural Glue

✒️
Real-world analogy: Punctuation marks in a sentence. A period ends a thought. Commas separate items in a list. C's punctuators — ;, { }, ( ), , — do exactly this job: ; ends a statement, { } groups a block, ( ) wraps function parameters.
punctuators_demo.c
punctuators_demo.c
C
void greet(char name[], int age)   // ( ) wraps parameters, , separates them
{                                        // { starts the function block
    printf("Hi %s, age %d\n", name, age);   // ; ends the statement
}                                        // } ends the function block
PunctuatorJob
;Ends a statement
{ }Groups a block of code (function body, loop body)
( )Wraps function parameters or groups expressions
,Separates items — parameters, array values, variables
[ ]Array indexing/declaration
put it together

Breaking Down One Full Line

Here's every token type from this lesson, all inside a single statement: int age = 25;

int age = 25 ;
Keyword Identifier Operator Constant Punctuator
💡 5 tokens, 5 categories, one complete statement. Every line of C you'll ever write is just a longer version of this same pattern — once you can spot which category each piece belongs to, unfamiliar code stops looking like noise.
quiz
Q

Quick Quiz

Question 1 of 5

What is a token in C?

Question 2 of 5

Why can't you name a variable "if"?

Question 3 of 5

In int totalArea = 50;, what kind of token is totalArea?

Question 4 of 5

Which of these is a character constant?

Question 5 of 5

What job does the semicolon (;) do as a punctuator?

Lesson Checklist

  • I can explain what a token is in my own words
  • I can name the 5 token types
  • I understand why keywords can't be used as variable names
  • I can distinguish an identifier from a keyword
  • I can identify integer, float, character, and string constants
  • I can spot operators and punctuators in a line of code
  • I can break a full statement into its individual tokens
  • I completed the quiz