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:
- Keywords
- Identifiers
- Constants
- Strings
- Operators
- 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
andage
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:
- Arithmetic Operators:
+
,-
,*
,/
,%
- Relational Operators:
==
,!=
,>
,<
,>=
,<=
- Logical Operators:
&&
,||
,!
- Assignment Operators:
=
,+=
,-=
,*=
,/=
- Increment/Decrement:
++
,--
- Bitwise Operators:
&
,|
,^
,~
,<<
,>>
- Conditional (Ternary) Operator:
?:
- Comma Operator:
,
- 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:
Symbol | Meaning |
---|---|
() | 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 Type | Description | Example |
---|---|---|
Keyword | Predefined word with a specific meaning | int , return |
Identifier | Name given to variables/functions | age , sum |
Constant | Fixed value | 10 , 'A' |
String | Sequence of characters | "Hello" |
Operator | Symbol performing an operation | + , - , = |
Special Symbol | Characters 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.