C++ MCQs with answers Page - 35

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 • 833.24K Points
Coach

Q. Select the right option.

Code:
extern int x;
int i;
  • (A) Line 1 and 2 declare x
  • (B) Line 1 declares the variable x and line 2 defines i
  • (C) Line 1 declares x, line 2 declares and defines i
  • (D) Line 1 declares and defines x, line 2 declares i

A

Admin • 833.24K Points
Coach

Q. Constants are also called ______

  • (A) Const
  • (B) Literals
  • (C) Preprocessor
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. What is the output of the following C++ code?

Code:
#include <iostream>
using namespace std;
int f = 100;
int main()
{
  int a;
  {
    int b;
    b = 10;
    a = 25;
    f = 35;
    cout << b << a << f;
  }
  a = 40;
  cout << a << f;
  return 0;
}
  • (A) 10253540100
  • (B) 1025352535
  • (C) 1025354035
  • (D) 1040253535

A

Admin • 833.24K Points
Coach

Q. How are the constants declared?

  • (A) With the keyword const
  • (B) With the keyword const and with the pre-processor #define.
  • (C) With the pre-processor #define.
  • (D) None of these

A

Admin • 833.24K Points
Coach

Q. What is the output of the following C++ code?

Code:
#include <iostream>
using namespace std;
int main()
{
   int  const  c = 9;
   cout << ++c;
   return 0;
}
  • (A) 9
  • (B) 10
  • (C) Error
  • (D) None of these

A

Admin • 833.24K Points
Coach

Q. What is the output of the following C++ code?

Code:
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
    int x = 5, y = 10, z = 15;
    int arr[3] = {&x, &y, &z};
    cout << *arr[*arr[1] - 7];
    return 0;
}
  • (A) 4
  • (B) 10
  • (C) 15
  • (D) Compiler error

A

Admin • 833.24K Points
Coach

Q. Can two functions declare (non-static) variables with the same name.

  • (A) Yes
  • (B) No
  • (C) No, it gives a runtime error.
  • (D) Yes, but this is not a good practice.

A

Admin • 833.24K Points
Coach

Q. Which of the following is the default return value of a function in C++?

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

A

Admin • 833.24K Points
Coach

Q. What is the output of the following C++ code?

Code:
#include <iostream>
using namespace std;
void f(int x, int y)
{
  x = 10;
  y = 5;
}
int main()
{
  int x = 5;
  f(x, x);
  cout << x;
  return 0;
}
  • (A) 10
  • (B) 5
  • (C) Compilation error.
  • (D) None of these

A

Admin • 833.24K Points
Coach

Q. What happens to a function defined in a class without any complex operation (like loop, etc.)?

  • (A) It becomes a virtual function of a class
  • (B) This becomes an inline function of a class.
  • (C) This becomes a default function of a class.
  • (D) The program displays an error

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