c tokens in c language | What are the types of C tokens?

What Are C Tokens?

In the C language, tokens are the smallest individual units of a program.
The C compiler uses these tokens to understand and translate your code into machine language.

A C program is made up of six main types of tokens:

  1. Keywords
  2. Identifiers
  3. Constants
  4. Strings
  5. Operators
  6. Special Symbols

1. Keywords

Keywords are reserved words that have a special meaning in C programming.
You cannot use them as variable names because they are predefined and used by the compiler.

✅ Example:

int main() {
    int age = 25;
    return 0;
}

Here, int, return, and main are keywords.

Common C Keywords:

int, float, char, if, else, for, while, do, return, void, break, continue, switch, case, default, struct, typedef, enum, const, sizeof, static, auto, goto, volatile, register, extern, signed, unsigned, long, short, double.

2. Identifiers

Identifiers are names you create to identify variables, functions, arrays, etc.

✅ Example:

int marks;
float percentage;

Here, marks and percentage are identifiers.

Rules for Identifiers:

  • Must start with a letter or underscore (_).
  • Can contain letters, digits, and underscores.
  • Are case-sensitive (Age and age are different).
  • Cannot be a keyword.

✅ Valid: count, student_name, _age
❌ Invalid: 9name, float, #mark

3. Constants

Constants are fixed values that don’t change during program execution.

Types of Constants:

  • Integer Constants: e.g. 10, -50, 0
  • Floating-point Constants: e.g. 3.14, -0.76
  • Character Constants: e.g. 'A', '9'
  • Enumeration Constants: e.g. enum days {Mon, Tue, Wed};

✅ Example:

const int maxScore = 100;

Here, maxScore is a constant value that cannot be modified.

4. Strings

Strings are a collection of characters enclosed in double quotes (” “).

✅ Example:

char name[] = "Sohail";

Here, "Sohail" is a string constant.
Strings always end with a null character (\0) in memory.

5. Operators

Operators are symbols used to perform operations on variables and values.

🧮 Types of Operators in C:

  1. Arithmetic Operators: +, -, *, /, %
  2. Relational Operators: ==, !=, >, <, >=, <=
  3. Logical Operators: &&, ||, !
  4. Assignment Operators: =, +=, -=, *=, /=
  5. Increment/Decrement: ++, --
  6. Bitwise Operators: &, |, ^, ~, <<, >>
  7. Conditional (Ternary) Operator: ?:
  8. Comma Operator: ,
  9. Sizeof Operator: sizeof()

✅ Example:

int a = 5, b = 10;
int sum = a + b;

Here, =, + are operators.

6. Special Symbols

These include punctuation marks and other symbols used to define program structure.

📘 Common Special Symbols:

SymbolMeaning
()Parentheses — used in function calls
{}Curly braces — used to define blocks
[]Square brackets — used in arrays
;Semicolon — marks the end of a statement
#Used in preprocessor directives
,Separator between variables
*Pointer symbol
&Address operator
->Structure member operator
.Member access operator

✅ Example:

#include <stdio.h>
int main() {
    printf("Hello World");
    return 0;
}

Here, #, (), {}, and ; are special symbols.

Types of C Tokens

Token TypeDescriptionExample
KeywordPredefined word with a specific meaningint, return
IdentifierName given to variables/functionsage, sum
ConstantFixed value10, 'A'
StringSequence of characters"Hello"
OperatorSymbol performing an operation+, -, =
Special SymbolCharacters with structural meaning{}, ;, ()

Final Thoughts

Understanding C tokens is like learning the alphabet of the C language.
Once you master these basic building blocks, you’ll be ready to write and understand complex programs easily.

Whether you’re preparing for an interview, college exam, or just brushing up your programming fundamentals — this concept is essential.

Previous articlewhere is the C programming language used?|c basic interview questions.

LEAVE A REPLY

Please enter your comment!
Please enter your name here