Setting an array to one value

后端 未结 5 846
孤城傲影
孤城傲影 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条回答
  •  旧时难觅i
    2020-12-09 18:08

    Depends on the value. If it's zero, use memset(a, 0, sizeof(a)). Otherwise, if it's a char array you can use memset with some other value. But memset always works at the char level so if your array is not char only zero is likely to be meaningful.

提交回复
热议问题