Aren't Boolean variables always false by default?

前端 未结 5 451
花落未央
花落未央 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:30

    Only global variables are assigned 0 (false) by default. Any local variables are given a non-zero garbage value, which would evaluate to true in a boolean variable.

提交回复
热议问题