Definition:
A pointer is a variable that stores the memory address of another variable.
Declaration Syntax:
data_type *pointer_name;
Example:
int a = 10;
int *ptr;
ptr = &a; // ptr holds the address of variable ‘a’
Accessing the value using a pointer:
printf(“%d”, *ptr); // Outputs 10
Why Pointers?
- Used in dynamic memory allocation
- To access array elements more efficiently
- Used in functions to return multiple values
- Essential for building complex data structures like linked lists
Pointer Operators:
- & (Address-of operator)
- * (Dereference operator)