I have the following code:
struct demo{
int *(*p)[];
};
int main() {
struct demo *demo_ptr;
int a = 1;
int b = 2;
int *arr[2];
arr[0] = &a;
arr[1] = &b;
for (int i = 0; i < 2; i++) {
printf("num in array = %d\n", *arr[i]);
}
demo_ptr->p = &arr;
for(int i = 0; i < 2; i++){
printf("num in array = %d\n", demo_ptr->(*p)[i]);
}
}
I'd like to access a and b by demo_ptr. But the code failed. How to assign value to p (a pointer to array of int pointers) declared in a struct, and how to access those ints in array through demo_ptr?