#include <iostream>
int main() {
// Declare an array of integers
int arr[] = {1, 2, 3, 4};
// Declare an array of pointers to integers
int *ptr_arr[4];
// Assign the addresses of the elements of arr to the elements of ptr_arr
for (int i = 0; i < 4; i++) {
ptr_arr[i] = &arr[i];
}
// Access the elements of arr through the pointers in ptr_arr
std::cout << "The elements of arr are: ";
for (int i = 0; i < 4; i++) {
std::cout << *ptr_arr[i] << " ";
}
std::cout << std::endl;
return 0;
}
output :
The elements of arr are: 1 2 3 4
0 Comments