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

What will be the output of the following C++ code?
Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        int num1 = 10;
        float num2 = 20;
        cout << sizeof(num1 + num2);
        return 0;
    }
A. 2
B. 4
C. 8
D. garbage
 
Answer: b
Explanation: In this program, integer is converted into float. Therefore the result of num1 and num2 is float. And it is returning the size of the float.
Output:
Code:
$ g++ size2.cpp
$ a.out
4
 

Tìm kiếm

Back
Top