#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?
!0
is abool
– Arnettearneysizeof
does not evaluate the expression. It works out the size of the type that would hold the result of the expression. – Loginovsizeof(int)
does not have to be4
, nor doessizeof(bool) = 1
. But it is enough for identification of this question. – Hilar