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 func(int a, bool flag = true)
{
if (flag == true )
{
cout << “Flag is true. a = ” << a;
}
else
{
cout << “Flag is false. a = ” << a;
}
}
int main()
{
func(200, false);
return 0;
}

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void func(int a, bool flag = true)
{
if (flag == true )
{
cout << "Flag is true. a = " << a;
}
else
{
cout << "Flag is false. a = " << a;
}
}
int main()
{
func(200, false);
return 0;
}
a) Flag is true. a = 200
b) Flag is false. a = 100
c) Flag is false. a = 200
d) Flag is true. a = 100

Answer: c
Explanation: In this program, we are passing the value, as it evaluates to false, it produces the output as following.
Output:
Flag is false. a = 200

Join The Discussion