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
Related Posts
What is the other name of the macro?
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
#define MAX 10
int main()
{
int num;
num = ++MAX;
cout << num;
return 0;
}What will be the output of the following C++ code?
#include <iostream>
using namespace std;
#define PR(id) cout << “The value of ” #id ” is “<< id
int main()
{
int i = 10;
PR(i);
return 0;
}What will be the output of the following C++ code?
#include <iostream>
using namespace std;
#define SquareOf(x) x * x
int main()
{
int x;
cout << SquareOf(x + 4);
return 0;
}What is the mandatory preprocessor directive for c++?
How many types of macros are there in c++?
Which symbol is used to declare the preprocessor directives?
Join The Discussion