memset an array to 1

后端 未结 4 1980
一生所求
一生所求 2020-12-16 03:10

I am trying to initialize a 2d array with some integer.If I initialize the array to 0 I am getting correct results but If I use some other integer I get some random values.<

4条回答
  •  清酒与你
    2020-12-16 03:51

    memset works on a byte-by-byte basis only. Zeroing out the bits works in general because all integral zeros are generally all-zero-bits, so that grouping four all-zero-bit bytes into one all-zero-bits int still gives you zero. For things that are not bytes, though, the simplest way to initialize all of them is just to explicitly initialize all of them.

提交回复
热议问题