What will be the output of the following C++ code?

#include <iostream>
    using namespace std;
    int main()
    {
        int num = 0x20 + 020 + 20;
        cout << sizeof(num)<<'\n';
        return 0;
    }

a) 2
b) 4
c) Depends on compiler
d) Garbage

1 thought on “What will be the output of the following C++ code?”

  1. d
    Explanation: The a as a integer will be converted to float while calculating the size. The value of any variable doesn’t modify inside sizeof operator. Hence value of variable a will remain 5.
    Output:
    $ g++ size3.cpp
    $ a.out
    4 5

Leave a Comment