Aren't Boolean variables always false by default?

前端 未结 5 452
花落未央
花落未央 2021-02-01 12:48

I had declared a Boolean variable bool abc; in a class and thought that it would be false by default. An if condition in my program, if (abc),

5条回答
  •  清歌不尽
    2021-02-01 13:22

    Yes. You need to either do bool x=false or bool x(false). Primitives that are not initialized may have any value.

    See Wikipedia

提交回复
热议问题