C++ MCQ Questions and Answers – Part 15
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; double & getVal() { double v = 12.99; double &val = v; return val; } int main() { double v = getVal(); cout << "The value = " << v; return 0; }
A 12
B 12.99
C Compilation error
D None of the above
[st_adsense]
2. Which header file is used to pass an unlimited number of arguments to a function?
A string.h
B stdlib.h
C stdarg.h
D None of the above
3. Which of the following statements allows you to overload a function in C++?
A Type
B Number of arguments
C Type and number of arguments
D None of the above
4. What is the output of the following C++ code?
#include <iostream> using namespace std; void display(double f) { cout << f << endl; } void display(int i) { cout << i << endl; } int main(void) { display(3); display(28.99); return 0; }
A 3
B 28.99
C Both A and B are true.
D None of the above
[st_adsense]
5. Which keyword is used to catch an exception in the code block?
A catch
B try
C throw
D None of the above
6. What happens if the exception is not caught in the program?
A Error
B The program will be executed.
C The block of this code will not be executed.
D None of the above
7. What is the maximum number of arguments or parameters that can be used in a function call?
A 64
B 256
C 255
D 254
8. Which keyword is used to define macros in C++?
A macro
B define
C #define
D None of the above
[st_adsense]
9. What is the output of the following C++ code?
#include <iostream> using namespace std; int sum(int a, int b, int c) { return a + b; } double sum(double a, double b, double c) { return a + b; } int main() { cout << sum(1, 2); cout << sum(1.5, 2.5); return 0; }
A 3 4
B 4 3
C 3 4.5
D Compilation error
10. Which symbol is used to declare preprocessor directives?
A $
B #
C %
D &
[st_adsense]