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

#include <iostream>
  using namespace std;
  int main()
  {
      int a = 5;
      float b;
      cout << sizeof(++a + b);
      cout << a;
      return 0;
  }

a) 2 5
b) 4 5
c) 4 6
d) 2 6

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

  1. b
    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