I have a class with a bool
data member that is not initialized by the constructor. If I do
cout << x.myBoolDataMember;
where x
is an object of this class in which the bool
has not been initialized, I sometimes get a random number rather than 0 or 1. (I'm using gcc
.) Is this behavior compliant with the Standard
?
Is this behavior compliant with the standard?
Yes! Using garbage values(uninitialized) in your code invokes Undefined Behavior
Yes. An uninitialized variable can have any value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With