C++ MCQs with answers Page - 2

Dear candidates you will find MCQ questions of C++ here. Learn these questions and prepare yourself for coming examinations and interviews. You can check the right answer of any question by clicking on any option or by clicking view answer button.
Share your questions by clicking Add Question

U

Uday Singh • 7.23K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    using namespace std;
    int function(int p = 12, int q)
    {
        int s;
        s = p + q;
        return s;
    }
    int main()
    {
        cout << function(15);
        return 0;
    }
  • (A) 15
  • (B) 12
  • (C) Runtime Error
  • (D) Compilation Error

U

Uday Singh • 7.23K Points
Tutor III

Q. What is the default return type of a function?

  • (A) char
  • (B) float
  • (C) void
  • (D) int

U

Uday Singh • 7.23K Points
Tutor III

Q. If we start our function call with default arguments means, what will be proceeding arguments?

  • (A) default arguments
  • (B) user argument
  • (C) empty arguments
  • (D) All of above

U

Uday Singh • 7.23K Points
Tutor III

Q. What we can’t place followed by the non-default arguments?

  • (A) default arguments
  • (B) trailing arguments
  • (C) both default & trailing arguments
  • (D) All of above

U

Uday Singh • 7.23K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    using namespace std;
    void function(int num1, int num2 = 12)
    {
        cout << "1st Number: " << num1<
        cout << "2nd Number: " << num2<   
      }
    int main()
    {
        function(2);
        function(5, 7);
        return 0;
    }
  • (A) 1st Number: 2 2nd Number: 12
  • (B) 1st Number: 5 2nd Number: 7
  • (C) 1st Number: 5 2nd Number: 7 1st Number: 2 2nd Number: 12
  • (D) 1st Number: 2 2nd Number: 12 1st Number: 5 2nd Number: 7

U

Uday Singh • 7.23K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    #include 
    using namespace std;
    string askMessage(string Message = "Please enter a message: ");
    int main()
    {
        string Input = askMessage();
        cout << "Here is your message: " << Input;
        return 0;
    }
    string askMessage(string Message)
    {
        string Input;
        cout << Message;
        cin >> Input;
        return Input;
    }
  • (A) Compilation Error
  • (B) Runtime Error
  • (C) Garbage value
  • (D) The message you entered

U

Uday Singh • 7.23K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    using namespace std;
    void function(int p, bool condition = true)
    {
        if (condition == true ) 
        {
            cout << "Condition is true. P = " << p;
        }
        else 
        {
            cout << "Condition is false. P = " << p;
        }
    }
    int main()
    {
        function(250, false);
        return 0;
    }
  • (A) Condition is true. P = 250
  • (B) 200
  • (C) Condition is false. P = 250
  • (D) True

U

Uday Singh • 7.23K Points
Tutor III

Q. Which value will it take when both user and default values are given?

  • (A) custom value
  • (B) default value
  • (C) user value
  • (D) All of above

U

Uday Singh • 7.23K Points
Tutor III

Q. Where can the default parameter be placed by the user?

  • (A) rightmost
  • (B) leftmost
  • (C) both rightmost & leftmost
  • (D) All of above

U

Uday Singh • 7.23K Points
Tutor III

Q. If the user did not supply the value, what value will it take?

  • (A) rise an error
  • (B) default value
  • (C) both rise an error & default value
  • (D) All of above

Loding content...

Download our easy to use, user friendly Android App from Play Store. And learn MCQs with one click.

Image

Login

Forgot username? click here

Forgot password? Click here

Don't have account? Register here.