There are several issues with your second piece of code:
void func1(void** arr) { } int main() { int** arr; int i[] = {1,2}; int j[] = {3,4}; *arr = i; *(arr+1) = j; func1(arr);
You never initialize arr to point to a pointer or an array of pointers to int . It is uninitialized, so its value can be anything. When you set *arr to i , you invoke undefined behavior.
In addition, int ** and void ** are not compatible types, you cannot directly convert them to another. The rationale for this is that on some rare systems, int * and void * may have a different view. Sending a pointer to int * as a pointer to void * would be just as wrong as casting a pointer to float as a pointer to double . On systems where the view is the same, you can simply write an explicit listing.
Here is the corrected version:
#include <stdlib.h> void func1(void **arr) { } int main(void) { int *int_pointer_array[2]; int **arr = &int_pointer_array; int i[] = { 1, 2 }; int j[] = { 3, 4 }; *arr = i; /* this line modifies int_pointer_array[0] */ *(arr+1) = j; /* this line modifies int_pointer_array[1] */ func1((void **)arr); return 0; }
source share