C++ 2D array to 1D array

后端 未结 4 1529
春和景丽
春和景丽 2020-12-17 00:23

I am attempting to convert a 2D array to 1D. I\'m extremely new to C/C++ but I think it\'s very important to learn how to convert a 2D array to 1D. So here I am stumbling u

4条回答
  •  时光说笑
    2020-12-17 00:58

    http://www.cplusplus.com/doc/tutorial/arrays/

    In that link look at the section on pseudo-multidimensional arrays.

    I've seen many examples that that get the subscripting algorithm wrong. If in doubt, trace it out. The order of sub-scripting a 2D array should go sequentially from 0-(HEIGHT*WIDTH-1)

    #define WIDTH 5
    #define HEIGHT 3
    
    int jimmy [HEIGHT * WIDTH];
    int n,m;
    
    int main ()
    {
      for (n=0; n

提交回复
热议问题