Default Arguments Cpp MCQ

Errorlogger
0
1. If the user didn’t supply the user value means, then what value will it take?
a) default value
b) rise an error
c) both a & b
d) none of the mentioned



2. Where does the default parameter can be placed by the user?
a) leftmost
b) rightmost
c) both a & b
d) none of the mentioned



3. Which value will it take when both user and default values are given?
a) user value
b) default value
c) custom value
d) none of the mentioned



4. What is the output of this program?
  1.     #include <iostream>
  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.     }
a) Flag is true. a = 200
b) Flag is false. a = 100
c) Flag is false. a = 200
d) Flag is true. a = 100



5. What is the output of this program?
  1.     #include <iostream>
  2.     #include <string>
  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.     }
a) 5
b) 6
c) the number you entered
d) compile time error



6. What is the output of this program?
  1.     #include <iostream>
  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.     }
a) 1st value: 1
    2nd value: 10
    1st value: 3
    2nd value: 4
b) 1st value: 1
    2nd value: 10
    1st value: 3
    2nd value: 10
c) compile time error
d) none of the mentioned



7. What we can’t place followed by the non-default arguments?
a) trailing arguments
b) default arguments
c) both a & b
d) none of the mentioned



8. If we start our function call with default arguments means, what will be proceeding arguments?
a) user argument
b) empty arguments
c) default arguments
d) none of the mentioned



9. What is the default return type of a function ?
a) int
b) void
c) float
d) char



10. What is the output of this program?
  1.     #include <iostream>
  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.     }
a) 15
b) 10
c) compile time error
d) none of the mentioned

Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !