#include <iostream>
int main()
{
std::cout<<sizeof(0);
return 0;
}
Here, sizeof(0)
is 4
in C++ because 0
is an integer rvalue.
But, If I write like this:
std::cout<<sizeof(!0);
here, sizeof(!0)
is 1
. But, !0
means it print 1
, which is also, int
type.
then, Why does sizeof(!0)
print 1
instead of 4
? What am I miss here?
The logical negation operator:
! rhs
If the operand is not bool, it is converted to bool using contextual conversion to bool: it is only well-formed if the declaration bool t(arg) is well-formed, for some invented temporary t.
The result is a bool prvalue.
And sizeof (bool)
which is implementation defined is 1 in your implementation.
!0
is a bool
.
sizeof(bool)
depends on implementation.
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