Is memset(&mystruct, 0, sizeof mystruct) same as mystruct = { 0 };?

后端 未结 4 1787
自闭症患者
自闭症患者 2020-12-05 23:57

I\'m reading about the initialized values by default of an array/struct and have this question:

is memset(&mystruct, 0, sizeof mystruct) same as <

4条回答
  •  一个人的身影
    2020-12-06 00:43

    This is a completely pedantic answer, but given that the internal representation of a null pointer is not guaranted to be 0 the behavior of memset versus brace-initialization would differ (memset would do the wrong thing). That said, I've never heard of an implementation that took on this liberty to have a non all 0 bit pattern for null.

提交回复
热议问题