- C Programming Tutorial
- C - Home
- Basics of C
- C - Introduction
- C - Features
- C - Basics
- C - History
- C - Structure of C Program
- C - Program Structure
- C - Hello World
- C - Compilation Process
- C - Comments
- C - Tokens
- C - Keywords
- C - Identifiers
- C - User Input
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Integer Promotions
- C - Type Conversion
- C - Type Casting
- C - Booleans
- Constants and Literals in C
- C - Constants
- C - Literals
- C - Escape sequences
- C - Format Specifiers
- Operators in C
- C - Operators
- C - Arithmetic Operators
- C - Relational Operators
- C - Logical Operators
- C - Bitwise Operators
- C - Assignment Operators
- C - Unary Operators
- C - Increment and Decrement Operators
- C - Ternary Operator
- C - sizeof Operator
- C - Operator Precedence
- C - Misc Operators
- Decision Making in C
- C - Decision Making
- C - if statement
- C - if...else statement
- C - nested if statements
- C - switch statement
- C - nested switch statements
- Loops in C
- C - Loops
- C - While loop
- C - For loop
- C - Do...while loop
- C - Nested loop
- C - Infinite loop
- C - Break Statement
- C - Continue Statement
- C - goto Statement
- Functions in C
- C - Functions
- C - Main Function
- C - Function call by Value
- C - Function call by reference
- C - Nested Functions
- C - Variadic Functions
- C - User-Defined Functions
- C - Callback Function
- C - Return Statement
- C - Recursion
- Scope Rules in C
- C - Scope Rules
- C - Static Variables
- C - Global Variables
- Arrays in C
- C - Arrays
- C - Properties of Array
- C - Multi-Dimensional Arrays
- C - Passing Arrays to Function
- C - Return Array from Function
- C - Variable Length Arrays
- Pointers in C
- C - Pointers
- C - Pointers and Arrays
- C - Applications of Pointers
- C - Pointer Arithmetics
- C - Array of Pointers
- C - Pointer to Pointer
- C - Passing Pointers to Functions
- C - Return Pointer from Functions
- C - Function Pointers
- C - Pointer to an Array
- C - Pointers to Structures
- C - Chain of Pointers
- C - Pointer vs Array
- C - Character Pointers and Functions
- C - NULL Pointer
- C - void Pointer
- C - Dangling Pointers
- C - Dereference Pointer
- C - Near, Far and Huge Pointers
- C - Initialization of Pointer Arrays
- C - Pointers vs. Multi-dimensional Arrays
- Strings in C
- C - Strings
- C - Array of Strings
- C - Special Characters
- C Structures and Unions
- C - Structures
- C - Structures and Functions
- C - Arrays of Structures
- C - Self-Referential Structures
- C - Lookup Tables
- C - Dot (.) Operator
- C - Enumeration (or enum)
- C - Structure Padding and Packing
- C - Nested Structures
- C - Anonymous Structure and Union
- C - Unions
- C - Bit Fields
- C - Typedef
- File Handling in C
- C - Input & Output
- C - File I/O (File Handling)
- C Preprocessors
- C - Preprocessors
- C - Pragmas
- C - Preprocessor Operators
- C - Macros
- C - Header Files
- Memory Management in C
- C - Memory Management
- C - Memory Address
- C - Storage Classes
- Miscellaneous Topics
- C - Error Handling
- C - Variable Arguments
- C - Command Execution
- C - Math Functions
- C - String Functions
- C - Static Keyword
- C - Random Number Generation
- C - Command Line Arguments
C Programming - C Tokens
![]() Share with a Friend |
C Programming - C Tokens
In the C programming language, a token is the smallest unit of a program. The compiler identifies tokens during the compilation process to understand the program structure.
Types of Tokens in C
- Keywords
- Identifiers
- Constants
- Strings
- Operators
- Special Symbols
- Keywords
- Reserved words with a predefined meaning in C.
- Cannot be used as identifiers (e.g., variable names or function names).
- Examples: :
int, float, if, else, while, return, break, void, char
- Example in Code:
int number = 10; // 'int' is a keyword
- Identifiers
- Names given to variables, functions, arrays, etc., defined by the programmer.
- Must begin with a letter or an underscore (_) and can be followed by letters, digits, or underscores.
- Case-sensitive.
- Rules:
- Cannot be a keyword.
- Should not contain spaces or special symbols (except _).
- Must be unique within its scope.
- Example in Code:
int age = 25; // 'age' is an identifier
- Constants
- Fixed values that do not change during program execution.
- Types:
- Integer Constants: Whole numbers (e.g., 10, -45).
- Floating-point Constants: Decimal numbers (e.g., 3.14, -0.99).
- Character Constants: A single character enclosed in single quotes (e.g., 'A').
- String Constants: A sequence of characters enclosed in double quotes (e.g., "Hello").
- Example in Code:
const float PI = 3.14; // 'PI' is a constant
- Strings
- A sequence of characters enclosed in double quotes.
- Represented as an array of characters internally.
- Example in Code:
char greeting[] = "Hello, World!";
- Operators
- Symbols used to perform operations on variables and values.
- Types:
- Arithmetic Operators: +, -, *, /, %
- Relational Operators: ==, !=, <, >, <=, >=
- Logical Operators: &&, ||, !
- Assignment Operators: =, +=, -=, *=, /=
- Bitwise Operators: &, |, ^, ~, <<, >>
- Example in Code:
int sum = a + b; // '+' is an arithmetic operator
- Special Symbols
- Special characters used in C for specific purposes.
- Examples:
- Braces {}: Define blocks of code.
- Parentheses (): Enclose function arguments or expressions.
- Brackets []: Enclose array elements.
- Comma ,: Separate multiple variables or parameters.
- Semicolon ;: End statements.
- Pound sign #: Preprocessor directives.
- Asterisk *: Pointer declaration or multiplication.
- Example in Code:
int arr[5] = {1, 2, 3, 4, 5}; // '{}' and '[]' are special symbols
Code Example with All Tokens
#include <stdio.h> // Preprocessor directive
int main() { // 'int' is a keyword, 'main' is an identifier
int num = 10; // 'int' is a keyword, 'num' is an identifier, '10' is a constant
float pi = 3.14; // 'float' is a keyword, 'pi' is an identifier, '3.14' is a constant
char c = 'A'; // 'char' is a keyword, 'c' is an identifier, 'A' is a character constant
printf("Number: %d\n", num); // 'printf' is a function, "Number: %d" is a string
return 0; // 'return' is a keyword, '0' is a constant
}
Summary of Tokens
| Token Type | Examples |
|---|---|
| Keywords |
int, float, return, if |
| Identifiers | num, pi, main |
| Constants |
10, 3.14, 'A' |
| Strings | "Hello", "Number: %d" |
| Operators | +, -, *, =, == |
| Special Symbols | {}, (), [], #, ; |
These tokens form the building blocks of any C program. Understanding them is crucial for writing and interpreting C code effectively.
