What will be the output of the following C++ code? [code] #include <iostream> using namespace std; enum cat {

KellyPoima

New member
What will be the output of the following C++ code?
Code:
    #include <iostream>
    using namespace std;
    enum  cat 
    {
        temp = 7
    };
    int main()
    {
        int age = 14;
        age /= temp;
        cout << "If you were cat, you would be " << age << endl;
        return 0;
    }
A. If you were cat, you would be 5
B. If you were cat, you would be 2
C. If you were cat, you would be 7
D. If you were cat, you would be 9
 
Answer: b
Explanation: The age will be divided by using compound assignment operator and so it will return the age of the cat according to your age.
Code:
$ g++ enum1.cpp
$ a.out
If you were cat, you would be 2
 

Tìm kiếm

Back
Top