+ 8
How can I declare an array of pointers..
I want to create two arrays of same length one which can store number another which can store its pointers..
6 Respostas
+ 11
To create an array of pointers, the following syntax may be used:
type* array_of_pointers [size_t size];
Eg - int* arr[6];
// An array of 6 int pointers, each having a capacity to store a reference of an element, or an int array...
+ 5
@Kinshuk Vasisht (+1)
I say, that's an array of pointers!
</declaration>
+ 5
Thanks.. @ Kinshuk Vasisht..
+ 4
but how will I associate that array of pointers... with my array of integer..
will this be like..
int a[6];
int *p[6];
*p[6]=&a[6];
+ 4
@Aryan Sharma
Use a for loop, in the following way :
for(size_t i = 0; i < size; i++)
{
arr[i] = &a[i];
}
Thats it. To use, dereference in the following way :
cout << *(arr[3]) << endl;
// Print 4th element of a.
+ 2
I think this code should resolve your query...
https://code.sololearn.com/cBf3xrkk8j0q/?ref=app