C++ MCQ Questions with Answers – Part 8
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; int main() { void x = 5, y = 5; int s; s = x + y; cout << s; return 0; }
A 10
B Compilation error
C Runtime error
D None of the above
2. Identify the wrong option.
A Enumerations are constants.
B Enums are user-defined types.
C Enumerations are the same as macros.
D The enumeration values start at 0 by default.
3. Select the right option.
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 and defines x, line 2 declares i
D Line 1 declares x, line 2 declares and defines i
4. What is the output of the following C++ code?
#include <stdio.h> int main() { char x = '\012'; printf("%d", x); return 0; }
A 10
B 12
C 0
D Compilation error
5. Constants are also called ______
A Const
B Preprocessor
C Literals
D None of the above
6. What is the output of the following C++ 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 1025354035
C 1040253535
D 1025352535
7. How are the constants declared?
A With the keyword const
B With the pre-processor #define.
C With the keyword const and with the pre-processor #define.
D None of the above
8. What is the output of the following C++ 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 the above
9. What is the output of the following C++ 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 10
B 15
C 4
D Compilation error
10. Can two functions declare (non-static) variables with the same name.
A No.
B Yes.
C Yes, but this is not a good practice.
D No, it gives a runtime error.