C++ MCQ Questions with Answers – Part 9
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. In which type are enums stored by the compiler?
A String
B Integer
C Float
D None of the above
2. What is the output of the following C++ code?
#include <iostream> using namespace std; void add() { static int s = 1; s++; cout << s; } int main() { add(); add(); add(); return 0; }
A 123
B 111
C 234
D 122
3. What is the output of the following C++ code?
#include <stdio.h> #include <iostream> using namespace std; int main() { char str[7] = "ABC"; cout << str[3]; cout << str; return 0; }
A CAB
B ABC
C ABCD
D C
4. To which type, enumerations can be assigned?
A Integer
B Float
C Enumeration
D All the answers are true
5. Which of the following statements is not true about preprocessor directives?
A These are lines read and processed by the preprocessor
B They do not produce code by themselves
C These must be written on a single line
D They end with a semi-colon
6. What is the output of the following C++ code?
#include <stdio.h> #include <iostream> using namespace std; int main() { int arr[] = {100, 200, 300}; cout << -2[arr]; return 0; }
A 300
B -300
C Compilation error
D Runtime error
7. Which of the following statements is true about the following instruction?
const int b = 100;
A Declares a variable b with 100 as initial value.
B Declare an integer b with 100 as initial value.
C Declares a constant b whose value will be 100.
D Creates a variable of type integer with the identifier b and 100 as value.
8. Which variable is equal to the size of enum variable?
A string var;
B float var;
C int var;
D None of the above
9. What is the output of the following C++ code?
#include <iostream> using namespace std; int main() { int x = 10; if (x < 10) { for (i = 0; i < 10; i++) cout << i; } else { cout << i; } return 0; }
A 12345678910
B 123456789
C 012345678
D Compilation error
10. The elements in a structure are also called _______
A objets
B members
C data
D None of the above