fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6. // Allocate RAM for a buffer to hold 5 pointers to int
  7. int** p_arr = malloc(sizeof(int*) * 5);
  8. // Allocate a buffer large enough to hold 10 int values, assigning it's
  9. // address to each of the 5 pointers in the RAM p_arr points to
  10. for(int i = 0; i < 5; i++)
  11. p_arr[i] = malloc(sizeof(int) * 10);
  12.  
  13. // Assign arbitrary values to the elements of the five 10-integer buffers
  14. for(int i = 0; i < 5; i++)
  15. for(int j = 0; j < 10; j++)
  16. *(*(p_arr + i) + j) = i * j;
  17.  
  18. // Print out the values of the elements of the five 10-integer buffers
  19. for(int i = 0; i < 5; i++)
  20. {
  21. for(int j = 0; j < 10; j++)
  22. printf("%02d ", p_arr[i][j]);
  23. putchar('\n');
  24. }
  25.  
  26. // Free each of the five 10-integer buffers
  27. for(int i = 0; i < 5; i++)
  28. free(p_arr[i]);
  29.  
  30. // Free the 5-pointer buffer
  31. free(p_arr);
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 5512KB
stdin
Standard input is empty
stdout
00 00 00 00 00 00 00 00 00 00 
00 01 02 03 04 05 06 07 08 09 
00 02 04 06 08 10 12 14 16 18 
00 03 06 09 12 15 18 21 24 27 
00 04 08 12 16 20 24 28 32 36