C++ MCQs with answers Page - 4

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 <iostream>
    #include <iomanip>
    using namespace std;
    void showDate(int mm, int dd, int yy)
    {
        cout << setfill('0');
        cout << setw(2) << mm << '/'
        << setw(2) << dd << '/'
        << setw(4) << yy << endl;
    }
    int main()
    {
        showDate(1, 1, 2019);
        return 0;
    }
  • (A) 01
  • (B) 02
  • (C) 2019
  • (D) 01/01/2019

U

Uday Singh • 7.23K Points
Tutor III

Q. Which function allows you to set minimum width for the next input?

  • (A) setwidth
  • (B) setfill
  • (C) setw
  • (D) All of above

U

Uday Singh • 7.23K Points
Tutor III

Q. Choose the correct formatted code.

  • (A) int main() { cout << 10;}
  • (B) int main(){ cout << “10”}
  • (C) int main() { cout << “10”; }
  • (D) All of above

U

Uday Singh • 7.23K Points
Tutor III

Q. What is the use of the indentation in c++?

  • (A) r distinguishes between comments and outer data
  • (B) distinguishes between comments and code
  • (C) both a and b
  • (D) to write multi line comment in c++

U

Uday Singh • 7.23K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    using namespace std;
    long fact (long p)
    {
        if (p > 1)
            return (p * fact (p + 1));
        else
            return (1);
    }
    int main ()
    {
        long n = 6;
        cout << n << "! = " << fact ( n );
        return 0;
    }
  • (A) 1
  • (B) 6
  • (C) segmentation fault
  • (D) compile time error

U

Uday Singh • 7.23K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    using namespace std;
    void square (int *p)
    {
	*p = (*p + 3) * (*p);
    }
    int main ( )
    {
	int n = 15;
        square(&n);
	cout << n;
	return 0;
    }
  • (A) 207
  • (B) 270
  • (C) 15
  • (D) 3

U

Uday Singh • 7.23K Points
Tutor III

Q. What is the output of this program?

Code:
#include 
    using namespace std;
    int add(int p, int q);
    int main()
    {
        int k = 7, L = 9;
        cout << add(k, L) << endl;
        return 0;
    }
    int add(int p, int q )
    {
        int sum = p + q;
        p = 10;
        return p + q;
    }
  • (A) 7
  • (B) 9
  • (C) 10
  • (D) 19

U

Uday Singh • 7.23K Points
Tutor III

Q. What is used to write multi line comment in c++?

  • (A) /$ …. $/
  • (B) //
  • (C) /* …. */
  • (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;
    int main()
    {
        /* this is comment*\
        cout << "Uday";
        return 0;
    }
  • (A) Uday
  • (B) Compilation Error
  • (C) Runtime Error
  • (D) Garbage value

U

Uday Singh • 7.23K Points
Tutor III

Q. What type of comments does c++ support?

  • (A) multiline
  • (B) single line
  • (C) multi-line and single line
  • (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.