How to initialize all elements in an array to the same number in C++

后端 未结 16 1969
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 07:17

I\'m trying to initialize an int array with everything set at -1.

I tried the following, but it doesn\'t work. It only sets the first value at -1.

in         


        
16条回答
  •  Happy的楠姐
    2020-12-05 07:52

    u simply use for loop as done below:-

    for (int i=0; i<100; i++)
    { 
    a[i]= -1;
    }
    

    as a result as u want u can get A[100]={-1,-1,-1..........(100 times)}

提交回复
热议问题