Create a pointer to two-dimensional array

后端 未结 10 1459
温柔的废话
温柔的废话 2020-11-22 07:16

I need a pointer to a static 2-dimensional array. How is this done?

static uint8_t l_matrix[10][20];

void test(){
   uint8_t **matrix_ptr = l_matrix; //wron         


        
10条回答
  •  旧巷少年郎
    2020-11-22 07:52

    You could also add an offset if you want to use negative indexes:

    uint8_t l_matrix[10][20];
    uint8_t (*matrix_ptr)[20] = l_matrix+5;
    matrix_ptr[-4][1]=7;
    

    If your compiler gives an error or warning you could use:

    uint8_t (*matrix_ptr)[20] = (uint8_t (*)[20]) l_matrix;
    

提交回复
热议问题