fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define N 100
  5.  
  6. void function(int n, int *a, int ***b)
  7. {
  8. int i;
  9.  
  10. if ((*b = (int **)malloc(sizeof(int **) * n)) == NULL)
  11. exit(1);
  12.  
  13. for (i = 0; i < N; i++)
  14. (*b)[i] = &a[i];
  15. }
  16.  
  17. int main(void)
  18. {
  19. int *a = (int *)malloc(sizeof(int) * N), **b;
  20. int i;
  21.  
  22. if (a == NULL)
  23. exit(1);
  24.  
  25. for (i = 0; i < N; i++)
  26. a[i] = i * 2;
  27.  
  28. function(N, a, &b);
  29.  
  30. for (i = 0; i < N; i++)
  31. printf("%d ", *b[i]);
  32. putchar('\n');
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 1964KB
stdin
Standard input is empty
stdout
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 174 176 178 180 182 184 186 188 190 192 194 196 198