31.
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
string askNumber(string prompt = "Please enter a number: ");
int main()
{
    string number = askNumber();
    cout << "Here is your number: " << number;
    return 0;
}
string askNumber(string prompt)
{
    string number;
    cout << prompt;
    cin << number;
    return number;
}

33.
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int add(int a, int b);
int main()
{
    int i = 5, j = 6;
    cout << add(i, j) << endl;
    return 0;
}
int add(int a, int b )
    {
        int sum = a + b;
        a = 7;
        return a + b;
    }

34.
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int max(int a, int b )
{
    return ( a > b ? a : b );
}
int main()
{
    int i = 5;
    int j = 7;
    cout << max(i, j );
    return 0;
}

37.
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void PrintSequence(int StopNum)
{
    int Num;
    Num = 1;
    while (true) 
    {
        if (Num >= StopNum)
            throw Num;
        cout << Num;
        Num++;
    }
}
int main(void)
{
    try 
    {
        PrintSequence(20);
    }
    catch(int ExNum)
    {
        cout << "Caught an exception with value: " << ExNum;
    }
    return 0;
}

40.
What will be the new value of x in the following C++ code?
#include <iostream>
using namespace std;
void fun(int &x)
{
    x = 20;
}
int main()
{
     int x = 10;
     fun(x);
     cout << "New value of x is " << x;
     return 0;
}

Read More Section(Functions and Procedures in C plus plus)

Each Section contains maximum 100 MCQs question on Functions and Procedures in C plus plus. To get more questions visit other sections.