Initialize 2D array

前端 未结 5 930
我寻月下人不归
我寻月下人不归 2020-12-02 16:33

I am trying to initialize a 2D array, in which the type of each element is char. So far, I can only initialize this array in the follow way.



        
5条回答
  •  孤街浪徒
    2020-12-02 16:51

    You can use for loop if you really want to.

    char table[][] table = new char[row][col];
    for(int i = 0; i < row * col ; ++i){
         table[i/row][i % col] = char('a' + (i+1));
    }
    

    or do what bhesh said.

提交回复
热议问题