C++ MCQ Questions with Answers – Part 12
Multiple choice questions and answers (MCQs) on C++ to prepare for exams, tests, and certifications. These questions are taken from a real written exam and some parts are taken from an interview. So you will find questions on basic techniques such as Variables, Operators, Conditional Statement, Functions, and more. This quiz will easily prepare anyone to pass their online test.
1. What is the output of the following C++ 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 the above
2. How many types of loops are there in C++?
A 1
B 2
C 3
D 4
3. What is the output of the following C++ 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 the above
4. 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.
5. What is the output of the following C++ 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
6. What is the output of the following C++ 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
7. What is the output of the following C++ 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
8. 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;};
9. Which of the following accesses the structure variable *a?
A a.var;
B a > var;
C a->var;
D a-var;
10. What is the output of the following C++ code?
#include <iostream> using namespace std; void display() void display() { cout << "Hello World!"; } int main() { display(); return 0; }
A Hello World!
B Hello World!Hello World!
C Compilation error.
D None of the above