Reputation: 351
I'm little bit confused about how to declare a pointer to array or void*.
let say :
void* myarr[20];
how to declare a pointer to "myarr?"
Upvotes: 2
Views: 7681
Reputation: 1349
void* (*myarr_ptr)[20] = myarr_ptr;
here is my test code:
#include <stdio.h>
int main()
{
int* myarr[20];
int * (*myarr_ptr)[20] = myarr;
printf("%p %p\n", myarr, *myarr_ptr);
return 0;
}
$ ./a.out
0x7fff8bd39dd0 0x7fff8bd39dd0
Upvotes: 1
Reputation: 310930
I think you mean a pointer to the first element of an array of pointers to void.
It is simply to do if you will use the following general approach. Let's assume that you have an array of some type T
T myarr[20];
then the definition of the pointer to the first element of the array will look like
T *ptr = myarr;
Now all what you need is substitute T
for you particulat type and you will get
void * myarr[20];
void * *ptr = myarr;
If you mean indeed a pointer to the array then approach is the following
T myarr[20];
T ( *ptr )[20] = &myarr;
Or if to substitute T
for void *
you will get
void * myarr[20];
void * ( *ptr )[20] = &myarr;
Upvotes: 3
Reputation: 9841
void** ptrToArrary = myarr_t; //pointing to base address of array.
Upvotes: -1