What is Array of pointer? Give one example.
Understanding Array of Pointer: Definition and Example
An array of pointers is an array where each element of the array holds a pointer to another object or variable. The elements of the array can be accessed by their index, and the pointer contained in each element can be used to access the object or variable it points to.
Here's an example of an array of pointers in C++, where each element of the array points to an integer variable:
#include<stdio.h>
int main() {
int* intPtrArray[5]; // declare an array of 5 pointers to integers
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
intPtrArray[0] = &a; // set the first element of the array to point to variable a
intPtrArray[1] = &b; // set the second element of the array to point to variable b
intPtrArray[2] = &c; // set the third element of the array to point to variable c
intPtrArray[3] = &d; // set the fourth element of the array to point to variable d
intPtrArray[4] = &e; // set the fifth element of the array to point to variable e
for (int i = 0; i < 5; i++) {
std::cout << *intPtrArray[i] << " "; // dereference the pointer and print the value it points to
}
return 0;
}
In this example, we declare an array of 5 pointers to integers (intPtrArray), and then set each element of the array to point to a different integer variable (a, b, c, d, and e). We then loop through the array and print out the values of the integers that the pointers point to.
Further Reading:
What is Array of pointer? Give one example.
Array of Pointer in c programming language
How to Create An Array Of Pointers in C – A Step-by-Step Guide
What is the difference between Array of pointer and Pointer to Array?
array of pointers, string functions, data manipulation, efficient algorithms
Dynamically Allocating Memory for an Array of Pointers
Virtual Shorting Using an array of Pointer
Write a C function that takes an array of pointers to strings and sorts them in lexicographic (dictionary) order.
Assignment of Array of Pointers in C
Enroll Now:
[ C-Programming From Scratch to Advanced 2023-2024] "Start Supercharging Your Productivity!"
Contact Us:
- For any inquiries, please email us at [[email protected]].
- Follow us on insta [ electro4u_offical_ ] for updates and tips.
Note: If you encounter any issues or specific errors when running this program, please let me know and I'll be happy to help debug them!