How to initialize a 2D array with all values same?

后端 未结 6 1627
独厮守ぢ
独厮守ぢ 2021-01-29 10:49

I want to initialize a 2D array with -1 as all the value. I used memset() for this.

#include 
using namespace std;

int dp[100]         


        
6条回答
  •  清酒与你
    2021-01-29 11:25

    You can't use memset in the global scope. It must be written in main scope.

    #include 
    using namespace std;
    
    int dp[100][100];
    
    int main() {
        memset(dp, -1, sizeof(dp));
        cout<

提交回复
热议问题