Setting an array to one value

后端 未结 5 835
孤城傲影
孤城傲影 2020-12-09 17:14

Is there an easier way in C to set an array to one value than using a for loop and going setting each value one by one?

5条回答
  •  不思量自难忘°
    2020-12-09 17:54

    You can set it to the same value, but only to 0

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

    initialize all elements to 0:

    int myArray[10] = { 0 }; // all elements 0
    

    There is an answer in that page for gcc as well.

提交回复
热议问题