how to return two dimensional char array c++?

前端 未结 8 2130
攒了一身酷
攒了一身酷 2020-12-03 15:23

i ve created two dimensional array inside a function, i want to return that array, and pass it somewhere to other function..

char *createBoard( ){  
  char          


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 15:42

    Don't return pointer to a local variable, as other mentioned. If I were forced to do what you want to achieve, first I'd go for std::vector. Since you haven't learnt std::vector, here is another way:

    void createBoard(char board[16][10])
    {  
      int j =0;int i = 0;
      for(i=0; i<16;i++){
            for( j=0;j<10;j++){   
                    board[i][j]=(char)201;
            }       
      }
    }
    

提交回复
热议问题