search

Home  >  Q&A  >  body text

c/c++中memset(str, 0, sizeof(str))用法?

c/c++中memset(str, 0, sizeof(str))memset(str, '/0', sizeof(str))

memset(str, '\0', sizeof(str))有什么区别呢?

PHPzPHPz2810 days ago1240

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-17 15:18:33

    '' refers to escaping a decimal value of 0 into an ascii character, so the ascii code value of '' is 0, so there is no difference. Also memset(str, '/0', sizeof(str)) may not be correct.

    It is customary to use '' to represent the end of a string. In terms of readability, it is more readable than using 0

    reply
    0
  • Cancelreply