How do I work with dynamic multi-dimensional arrays in C?

前端 未结 9 1734
庸人自扰
庸人自扰 2020-11-22 05:14

Does someone know how I can use dynamically allocated multi-dimensional arrays using C? Is that possible?

9条回答
  •  醉梦人生
    2020-11-22 05:55

    malloc will do.

     int rows = 20;
     int cols = 20;
     int *array;
    
      array = malloc(rows * cols * sizeof(int));
    

    Refer the below article for help:-

    http://courses.cs.vt.edu/~cs2704/spring00/mcquain/Notes/4up/Managing2DArrays.pdf

提交回复
热议问题