How to memset a 2D arrray?

前端 未结 1 526
悲哀的现实
悲哀的现实 2021-01-26 03:55

I want to memset a 2D array to 0. Here\'s my code.. But it always giving me seg fault;

      bool **visited=new bool*[m];
         for(int i=0;i

        
1条回答
  •  [愿得一人]
    2021-01-26 04:18

    Your array is not contiguous since it is not actually a multi-dimensional array. It's an array of arrays, sometimes known as a jagged array.

    So, your rows can, and will, be disjoint. Hence you'll need to call memset on each row.

    bool **visited=new bool*[m];
    for(int i=0;i

    Although, I can't refrain from pointing out that you should probably be using C++ features rather than writing what appears to be C with the use of the new operator.

    0 讨论(0)
提交回复
热议问题