memset function in c language

后端 未结 3 638
刺人心
刺人心 2021-01-31 11:21

I am studying the memset function now, but all the examples are regarding to char array as following:

char a[100];
memset(a, 0, 100);

it will s

3条回答
  •  自闭症患者
    2021-01-31 11:51

    For static-sized and variable-length arrays, you can just

      foo [...];
    memset (foo, 0, sizeof (foo)); // sizeof() gives size of entity in bytes
    


    Rule of thumb: Never hardcode [data sizes].

    (This does not work if you pass arrays as function arguments: Behaviour of Sizeof in C )

提交回复
热议问题