Original Post
I am having trouble getting this code to work. Is this correct ?
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 typedef struct x
6 {
7 void **vp;
8 struct x *next;
9 }dev;
10
11 int main()
12 {
13 dev d;
/* i want to allocate 2X2 array if ints, */
14 d.vp = (void **)malloc(2*sizeof(int *));
15 d.vp[0] = (void *)malloc(2*sizeof(int));
16 d.vp[1] = (void *)malloc(2*sizeof(int));
17 /* are these assignment correct *?
18 *(int*)(*(d.vp+0)+0) = 100;
19 *(int*)(*(d.vp+0)+1) = 34;
20 *(int*)(*(d.vp+1)+0) = 1134;
21 *(int*)(*(d.vp+1)+1) = 2134;
22 /* say if i have a int **i, populated as 2X2 array as above can i do a : d.vp = &i[0]; to make void ** point to int** */
22 free(d.vp);
23 return 0;
24 }
The comments in the code indicate what I am confused about/what I am trying to achieve. Any help?