Initializing variables in C

后端 未结 10 693
长情又很酷
长情又很酷 2020-12-02 12:21

I know that sometimes if you don\'t initialize an int, you will get a random number if you print the integer.

But initializing everything to zero seems

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 13:11

    Static and global variables will be initialized to zero for you so you may skip initialization. Automatic variables (e.g. non-static variables defined in function body) may contain garbage and should probably always be initialized.

    If there is a non-zero specific value you need at initialization then you should always initialize explicitly.

提交回复
热议问题