Different outputs of sizeof operator in C and C++

Viewed 842

Different outputs of sizeof() operator in C and C++.

In C:

int main() 
{
    printf("%zu\n", sizeof(1 == 1));
    return 0;
}

output:

4

In C++:

int main() 
{
    std::cout << sizeof(1 == 1) << std::endl;
    return 0;
}

output:

1

Questions:

  • Why are the outputs different?
  • Is sizeof independent of the OS or compiler?
  • Is it dependent on language?
3 Answers
Related