fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void check(int num, int **points){
  5. int (*format)[4] = (int (*)[4])malloc(sizeof(int[num][4])); //fixed
  6. for (int idx=0; idx < num; idx++){
  7. for (int jdx = 0; jdx < 4; jdx++)
  8. format[idx][jdx] = points[idx][jdx];
  9. }
  10. cout << points[2][3]<<"\n";
  11. cout << format[3][3];
  12. }
  13.  
  14. int main() {
  15. int r = 3, c = 4, i, j, count;
  16.  
  17. int **arr = (int **)malloc(r * sizeof(int *));
  18. for (i=0; i<r; i++)
  19. arr[i] = (int *)malloc(c * sizeof(int));
  20.  
  21. count = 0;
  22. for (i = 0; i < r; i++)
  23. for (j = 0; j < c; j++)
  24. arr[i][j] = ++count;
  25.  
  26. check(r, arr); //these are fixed
  27. return 0;
  28. }
Success #stdin #stdout 0s 4264KB
stdin
Standard input is empty
stdout
12
0