How to initialize all members of an array to the same value?

后端 未结 23 1909
清歌不尽
清歌不尽 2020-11-21 04:34

I have a large array in C (not C++ if that makes a difference). I want to initialize all members of the same value.

I could swear I

23条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-21 05:05

    #include
    int main(){
    int i,a[50];
    for (i=0;i<50;i++){
        a[i]=5;// set value 5 to all the array index
    }
    for (i=0;i<50;i++)
    printf("%d\n",a[i]);
       return 0;
    }
    

    It will give the o/p 5 5 5 5 5 5 ...... till the size of whole array

提交回复
热议问题