What will be the output of the following C++ code? [code] #include <iostream> using namespace std; int main() {

Tiên Hương

New member
What will be the output of the following C++ code?
Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        int a = 5;
        float b;
        cout << sizeof(++a + b);
        cout << a;
        return 0;
    }
A. 2 6
B. 4 6
C. 2 5
D. 4 5
 
Answer: 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:
Code:
$ g++ size3.cpp
$ a.out
4 5
 

Tìm kiếm

Back
Top