Accessing an entire row of a multidimensional array in C++

前端 未结 3 820
鱼传尺愫
鱼传尺愫 2021-01-12 13:47

How would one access an entire row of a multidimensional array? For example:

int logic[4][9] = {
    {0,1,8,8,8,8,8,1,1},
    {1,0,1,1,8,8,8,1,1},
    {8,1,0         


        
3条回答
  •  情歌与酒
    2021-01-12 14:08

    As well as decaying the array to a pointer, you can also bind it to a reference:

    int (&temp)[9] = logic[2];
    

    One advantage of this is it will allow you to use it C++11 range-based for loops:

    for (auto t : temp) {
      // stuff
    }
    

提交回复
热议问题