C++ MCQs with answers Page - 2

Here, you will find a collection of MCQ questions on C++. Go through these questions to enhance your preparation for upcoming examinations and interviews.

To check the correct answer, simply click the View Answer button provided for each question.

Have your own questions to contribute? Click the button below to share your MCQs with others!

+ Add Question

A

Admin • 833K Points
Coach

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

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

A

Admin • 833K Points
Coach

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

A

Admin • 833K Points
Coach

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

A

Admin • 833K Points
Coach

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

A

Admin • 833K Points
Coach

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

A

Admin • 833K Points
Coach

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

A

Admin • 833K Points
Coach

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

A

Admin • 833K Points
Coach

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

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

A

Admin • 833K Points
Coach

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

A

Admin • 833K Points
Coach

Q. What will happen when we use void in argument passing?

  • (A) Maybe or may not be return any value to its caller
  • (B) It will not return value to its caller
  • (C) It will return value to its caller
  • (D) All of above

Add MCQ in this Category

If you want to share an MCQ question in this category, it's a great idea! It will be helpful for many other students using this website.

Share Your MCQ