CPP

CPP

Default Arguments has 10 Questions

If the user didn't supply the value, what value will it take?

default value
rise an error
both a & b
none of the mentioned
Where can the default parameter be placed by the user?

leftmost
rightmost
both a & b
none of the mentioned
Which value will it take when both user and default values are given?

user value
default value
custom value
none of the mentioned
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     void func(int a, bool flag = true)
  4.     {
  5.         if (flag == true ) {
  6.             cout << "Flag is true. a = " << a;
  7.         }
  8.         else {
  9.             cout << "Flag is false. a = " << a;
  10.         }
  11.     }
  12.     int main()
  13.     {
  14.         func(200, false);
  15.         return 0;
  16.     }

Flag is true. a = 200
Flag is false. a = 100
Flag is false. a = 200
Flag is true. a = 100
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     string askNumber(string prompt = "Please enter a number: ");
  5.     int main()
  6.     {
  7.         string number = askNumber();
  8.         cout << "Here is your number: " << number;
  9.         return 0;
  10.     }
  11.     string askNumber(string prompt)
  12.     {
  13.         string number;
  14.         cout << prompt;
  15.         cin >> number;
  16.         return number;
  17.     }

5
6
the number you entered
compile time error
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     void Values(int n1, int n2 = 10)
  4.     {
  5.         using namespace std;
  6.         cout << "1st value: " << n1;
  7.         cout << "2nd value: " << n2;
  8.     }
  9.     int main()
  10.     {
  11.         Values(1);
  12.         Values(3, 4);
  13.         return 0;
  14.     }

1st value: 1 ????2nd value: 10 ????1st value: 3 ????2nd value: 4
1st value: 1 ????2nd value: 10 ????1st value: 3 ????2nd value: 10
compile time error
none of the mentioned
What we can't place followed by the non-default arguments?

trailing arguments
default arguments
both a & b
none of the mentioned
If we start our function call with default arguments means, what will be proceeding arguments?

user argument
empty arguments
default arguments
none of the mentioned
What is the default return type of a function?

int
void
float
char
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     int func(int m = 10, int n)
  4.     {
  5.         int c;
  6.         c = m + n;
  7.         return c;
  8.     }
  9.     int main()
  10.     {
  11.         cout << func(5);
  12.         return 0;
  13.     }

15
10
compile time error
none of the mentioned