C++11 says (3.9 "Types" [basic.types]):
The value representation of an object is the set of bits that hold the
value of type T. For trivially copyable types, the value
representation is a set of bits in the object representation that
determines a value, which is one discrete element of an
implementation-defined set of values
And (3.9.1 "Fundamental types" [basic.fundamental]):
For character types, all bits of the object representation participate
in the value representation. For unsigned character types, all
possible bit patterns of the value representation represent numbers.
These requirements do not hold for other types.
...
Values of type bool are either true or false
And finally, 5 "Expressions" [expr] says:
If during the evaluation of an expression, the result is not
mathematically defined or not in the range of representable values for
its type, the behavior is undefined.
What is happening is that when you write the value 123 to the memory that the bool
object occupies (through the char* p
), you're writing something that can't be represented in the bool
object's 'value representation'. So when you subsequently access that object through the lvalue b
the program exhibits undefined behavior and you have a bool
object that is neither true
nor false
.
And to answer your question about what the value of true
is: the standard never actually specifies. It does specify that the true
is one of the two values a bool
type can represent (the other being false
of course). The standard also specifies that true
readily converts to 1 and vice versa, 1 readily converts to true
. These conversion happen so naturally and easily that I think that nearly everyone considers true
to have the value 1.
One thing to remember is that nearly any non-zero integral value will readily convert to true
- not just 1. However that doesn't happen in your example for the value 123 because in that expression it is being written to an lvalue with char
type so no conversion to bool
occurs.