Why does malloc initialize the values to 0 in gcc?

前端 未结 9 1967
慢半拍i
慢半拍i 2020-11-22 16:34

Maybe it is different from platform to platform, but

when I compile using gcc and run the code below, I get 0 every time in my ubuntu 11.10.

#include         


        
9条回答
  •  粉色の甜心
    2020-11-22 16:53

    The standard does not dictate that malloc() should initialize the values to zero. It just happens at your platform that it might be set to zero, or it might have been zero at the specific moment you read that value.

提交回复
热议问题