C++ MCQs with answers Page - 31

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. What is the output of the following code?

Code:
#include <iostream>
using namespace std;
int main()
{
   char *p;
   char str[] = "StackHowTo";
   p = str;
   p += 5;
   cout << p;
  return 0;
}
  • (A) StackHowTo
  • (B) Stack
  • (C) HowTo
  • (D) H

A

Admin • 833.24K Points
Coach

Q. Select the wrong option?

  • (A) void is used when the function does not return a value
  • (B) void is also used when the value of a pointer is null
  • (C) void is used as a base type for pointers to objects of unknown type
  • (D) void is a special type

A

Admin • 833.24K Points
Coach

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

Code:
#include <iostream>
using namespace std;
void carree(int *x)
{
  *x = (*x + 1) * (*x);
}
int main()
{
  int n = 10;
  carree(&n);
  cout << n;
  return 0;
}
  • (A) 100
  • (B) 110
  • (C) 101
  • (D) None of these

A

Admin • 833.24K Points
Coach

Q. How many types of loops are there in C++?

  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4

A

Admin • 833.24K Points
Coach

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

Code:
#include <iostream>
using namespace std;
int sum(int x, int y);
int main()
{
  int i = 1, j = 2;
  cout << sum(i, j) << endl;
  return 0;
}
int sum(int x, int y )
{
  int s = x + y;
  x = 2;
  return x + y;
}
  • (A) 3
  • (B) 4
  • (C) Compilation error
  • (D) None of these

A

Admin • 833.24K Points
Coach

Q. Which loop is best used when the number of iterations is known in advance?

  • (A) do while
  • (B) while
  • (C) for
  • (D) all loops require that the number of iterations be known

A

Admin • 833.24K Points
Coach

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

Code:
#include <iostream>
using namespace std;
void Sum(int a, int b, int & c)
{
  a = b + c;
  b = a + c;
  c = a + b;
}
int main()
{
  int a = 2, b =1;
  Sum(a, b, b);
  cout << a << " " << b;
  return 0;
}
  • (A) 2 1
  • (B) 2 3
  • (C) 2 5
  • (D) 3 5

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 arr[] = {1, 2, 3, 4, 5};
  int *ptr = (arr + 1);
  cout << *arr + 2;
  return 0;
}
  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4

A

Admin • 833.24K Points
Coach

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

Code:
#include <iostream>
using namespace std;
main()
{
  double x = 15.564702;
  float y = 5.99;
  int z ,w;
  z = (int) x;
  w = (int) y;
  cout << z <<<< w;
  return 0;
}
  • (A) 15 6
  • (B) 14 6
  • (C) 15 5
  • (D) None of the above

A

Admin • 833.24K Points
Coach

Q. Which of the following is a correctly defined structure?

  • (A) struct {int x;}
  • (B) struct myStruct {int x;}
  • (C) struct myStruct int x;
  • (D) struct myStruct {int x;};

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