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>
using namespace std;
void Values(int n1, int n2 = 10)
{
using namespace std;
cout << “1st value: ” << n1;
cout << “2nd value: ” << n2;
}
int main()
{
Values(1);
Values(3, 4);
return 0;
}

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void Values(int n1, int n2 = 10)
{
using namespace std;
cout << "1st value: " << n1;
cout << "2nd value: " << n2;
}
int main()
{
Values(1);
Values(3, 4);
return 0;
}
a) 1st value: 1
10
3
4
b) 1st value: 1
10
3
10
c) compile time error
d) runtime error

Answer: a
Explanation: In this program, We are passing the values as by default values rules it is working.
Output:
1st value: 1
2nd value: 10
1st value: 3
2nd value: 4

Join The Discussion