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

What will be the output of the following C++ code?
Code:
    #include <iostream>
    using namespace std;
    void PrintSequence(int StopNum)
    {
        int Num;
        Num = 1;
        while (true)
        {
            if (Num >= StopNum)
                throw Num;
            cout << Num << endl;
            Num++;
        }
    }
    int main(void)
    {
        try
        {
            PrintSequence(2);
        }
        catch(int ExNum)
        {
            cout << "exception: " << ExNum << endl;
        }
        return 0;
    }
A. 1
B. exception: 2
C.
1
exception: 2
D. exception: 4
 

Tìm kiếm

Back
Top