Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

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;
}

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;
}
a) 5
b) 6
c) the number you entered
d) compile time error

Answer: c
Explanation: In this program, we are getting a number and printing it.
Output:
Please enter a number:
5
Here is your number:5

Join The Discussion