Pointer array
Pointer Array A pointer array is a collection of memory addresses stored in contiguous memory locations. Each address in the array holds the memory addr...
Pointer Array A pointer array is a collection of memory addresses stored in contiguous memory locations. Each address in the array holds the memory addr...
Pointer Array
A pointer array is a collection of memory addresses stored in contiguous memory locations. Each address in the array holds the memory address of the next element in the sequence.
Example:
int numbers[5] = {1, 2, 3, 4, 5};
int *ptr_to_numbers = &numbers[0]; // 'ptr_to_numbers' is a pointer variable
// Accessing elements using pointer arithmetic
int number = numbers[ptr_to_numbers - 1];
Benefits of using pointer arrays:
Dynamic memory allocation: You can allocate memory for an array during runtime.
Efficient data access: They allow you to access elements in an array using a single memory address.
Passing arrays as arguments: You can pass pointer arrays to functions or methods.
Note:
Pointer array elements are stored in contiguous memory locations, with the first element stored at the lowest address.
The size of the array is determined by the number of elements it contains.
Pointer arithmetic is used to access elements in a pointer array. For example, numbers[ptr_to_numbers - 1] accesses the element at the address stored in ptr_to_numbers - 1