Try to answer these 600+ C++ MCQs and check your understanding of the C++ subject.
Scroll down and let's begin!
A. Operating on Objects in Design
B. Object-Oriented Design
C. Overly Objective Design
D. Object-oriented database
A. Always 0.
B. It's depend of double implementation, usually not exactly zero.
C. Always not 0.
A. private
B. protected
C. public
D. Visibility is defined for classes only.
A. true
B. false
A. inline functions.
B. recursive functions.
C. function overloading.
A. int a; b; c;
B. int a, b, c;
C. int a:
A. Hash symbol (#)
B. Colon (:)
C. Semi-colon (;)
D. Addition sign (+)
A. int myFunction( int a, int b)
B. myFunction( int a, int b)
C. void myFunction( int a, int b)
A. declare x as integer;
B. int x;
C. x int;
D. int<x>;
E. x is integer;
A. stop when loop
B. do while loop
C. for loop
A. char
B. wide
C. bool
A. ?
B. ,
C. :%
D. ::
A. int
B. real
C. float
D. double
A. None of these options
B. if( (sum == 10) || (total < 20) )printf(
C. if( (sum == 10) && (total < 20) )printf(
D. ctrl+alt+del
A. myfunction(void)
B. void myfunction()
C. myfunction()
A. CHAR
B. char
C. character
D. Char
A. a = b;
B. a = &b;
C. a = *b;
A. Both of these
B. /* this is a comment */
C. // this is a comment
A. True
B. False
A. The value of a cannot change from 50.
B. The initial value of a is 50 but you can change it.
C. none of these
A. a leading //.
B. all of these
C. a leading /**.
A. 4
B. 4.36
C. 4.4
D. 5
A. The maximum integer value that can be placed in the array.
B. The initial value of the first array element.
C. The number of integer elements the array shall hold.
A. printmsg();
B. void printmsg();
C. printmsg;
A. Yes
B. No
C. Depends on the situation.
A. reduce code duplication
B. templates are typesafe
C. all of these
D. increase code flexibility
A. int myFunction( int a, int b);
B. all of these
C. int myFunction(int, int);
A. none of these
B. can be accessed by all objects of the same class.
C. their values will change for each object of the same class.
A. returns the maximum value of arg
B. returns the size in bytes of arg
C. returns the length in characters of arg
A. You can declare functions in a class, you cannot declare functions in a struct.
B. They are the same.
C. You cannot overload an operator in a struct.
D. The members of a class are private by default, and the members of a struct are public by default.
A. True
B. False
A. 4,4,4,4
B. 0,1,2,3
C. 4,5,6,7
D. 1,2,3,4
A. It will declare a new variable a and set it to 97 (assuming a machine that uses ASCII).
B. It will declare a new variable a and set it to its previous value.
C. It will cause an infinite loop.
D. Nothing, it is an error and won't compile.
A. Freeing memory which has already been freed.
B. All of these
C. Using an address before memory is allocated and set.
A. value contained in the address of a
B. address of a
C. 25
A. dynamic_cast
B. reinterpret_cast
C. unknown_cast
D. const_cast
A. *(myItem.units)
B. myItem->units
C. myItem.units
A. different types in C++.
B. alternate names for existing types in C++.
A. m_test
B. 1_str
C. class
A. It tells the program to include the standard library header files.
B. It tells the preprocessor to include the iostream standard file.
C. It tells the preprocessor to include the iostream standard file only if it it required by the program.
A. rectangle::move circle::move shape::move
B. Compile error
C. Runtime error
D. shape::move shape::move shape::move
E. shape::move circle::move rectangle::move
A. Declares a volatile virtual function.
B. Declares a pure virtual function.
C. Causes a compiler error.
D. Declares a default virtual function.
A. Initializes a vector with 5 elements of value 0.
B. Initializes a vector with an element with the value 5.
A. In all directories specified by the PATH environment variable on the machine.
B. In the default directories where it is configured to look for the standard header files
C. The same directory that includes the file containing the directive.
A. Nothing, that is not a valid C++ expression.
B. 0
C. -2
D. 2
E. 4
A. True
B. False
A. The function must be defined as the friend function.
B. The function must be defined inside the class.
C. The function must be defined outside the class.
A. No difference.
B. There are no inheritances with structs. Classes may be derived.
C. Structs only allow variable definitions. Classes also allow function definition.
D. Structs have public privacy by default, classes use private.
A. 8
B. 6
C. 7
A. The second one is illegal.
B. The first one is illegal.
C. None, they are equivalent.
D. One of them takes no value, the other takes any value.
A. Both of the other answers are correct.
B. Cannot redefine the meaning of built in types
C. Cannot have default arguments
A. ofstream
B. fstream
C. ifstream
D. All of the answers are correct.
A. an integer string
B. a string
C. a wide character string
A. No difference, all three are allocated memory sequentially
B. There is no difference, all three are allocated memory randomly
C. Union and class data members are allocated in memory sequentially whereas struct data members are allocated memory randomly
D. Struct and class data members are allocated in memory sequentially whereas a union is allocated memory randomly
E. Struct and class data members are allocated in memory sequentially whereas a union is allocated enough memory for the largest data member only
A. auto
B. var
C. abstract
D. virtual
A. This code will correctly free memory
B. This code has undefined behavior
A. It prevents a single-argument constructor from being used in an implicit conversion
B. It requires a variable to reside in main memory instead of a processor's cache
C. It makes the declaration of a default constructor mandatory
A. A class member function that you expect to be redefined in derived classes.
B. A class member function that must be redefined in derived classes.
C. A class member function which does not need to be defined in the base class.
A. O(n/2)
B. O(logn)
C. O(n)
D. O(1)
A. delete a[3];
B. delete[] a;
C. delete a;
D. delete a[];
E. delete[3] a;
A. ==
B. ?
C. *
D. []
E. ++
A. std::regex e ("\\b(sub)([^ ]*)");
B. int (*minus)(int, int) = subtract;
C. bool is_odd = [](int n) {return n%2==1;};
A. absence of a type for the pointer.
B. none of these
C. pointer has a NULL value.
A. this->parent->foo();
B. Parent.foo();
C. Parent::foo();
D. Parent instance; instance.foo;
A. nest namespaces
B. support closures
C. prevent external access to declarations local to a compilation unit
D. disambiguate declarations from other namespaces
A. No.
B. Yes.
C. Yes, but only if you #include
D. No, you need to add "const" before "char".
A. 0 to 2,147,483,647
B. 0 to 65,535
C. 0 to 4,294,967,295
D. 0 to 255
A. blue
B. color.blue
C. color[1]
D. color::blue
A. a newline (\n)
B. a tab (\t)
C. a backslash (\)
A. C++ standard guarantees that inlining does not result in any adverse side-effects
B. The size of program's stack segment increases
C. The size of the compiled binary increases
D. The size of program's heap segment increases
A. All
B. Standard
C. None
A. ++i
B. i++
C. Both are equally fast.
A. The code will not compile
B. 1
C. 2
D. 0
A. 1
B. 1.0
C. 3.03
D. 1.01
E. None, that is an invalid mix of types.
A. protected
B. public
C. B does not inherit access to z from A.
D. private
A. Copy Constructor
B. Default constructor
C. Both of these
A. A union is the size of whichever data member is initialized whereas the size of a struct is the sum of the size of the struct data members
B. A union is the size of its largest data member whereas the size of a struct is the sum of the size of the struct data members
C. No difference; they are the sum of the sizes of their respective data members
D. A union is the size of its largest data member whereas the size of a struct is at least the sum of the size of the struct data members
A. This is invalid C++ code
B. 80
C. Depends
D. 120
E. 4
A. Depend upon the Execution.
B. Infinite loop.
C. Finite loop.
D. All are wrong
A. No. The constructor is not public.
B. No. c0 x2 ( x1 ) will return error.
C. No. struct types do not have constructors.
D. Yes.
A. hash_multiset
B. hash_set
C. hash_table
D. hash_map
E. hash_multimap
A. at is always bounds checked. operator[] is not.
B. at is not always bounds checked. operator[] is.
C. at is equivalent to operator[]
A. 4
B. Compile error.
C. 3
D. 2
A. A is defined to be a constant function in namespace B taking arguments of types D and E, returning a pointer to type C.
B. C is defined to be a constant member function pointer of class B taking arguments of types D and E, returning type A.
C. B is defined to be a class containing a constant member function called A, taking arguments of types D and E, returning a pointer to type C.
A. Compile error
B. John Doe
C. 42
A. A struct declaration with 2 arrays of int.
B. A bit field structure declaration.
C. A struct with in place initialization of its members.
D. Invalid C++ code.
E. A bit selector declaration.
A. O(log(n))
B. O(n)
C. O(n^2)
D. O(1)
A. It depends on the host computer's word size.
B. Nothing, void doesn't have a size.
C. 0
D. 1
E. 4
A. None of these
B. 3
C. 333
D. Program fails during compilation
E. 000
A. 3
B. Undefined behavior
C. 5
D. Compile error: malformed attribute.
E. 4
A. Only by dirty hack with reinterpret_cast.
B. No. Only allocation on stack or in dynamic memory is allowed.
C. Yes, placement new does this.
A. none, the code wont compile
B. c++11
C. c++03
D. c++98
E. c++0x
A. 0x98765432
B. 1
C. This is undefined behavior
D. 0
E. 0x4C3B2A19
A. 3
B. no output; program is ill-formed
C. 0
D. 2
A. 1,2,3,4,5,6,7,8,9,10
B. 10,11,12,13,14,15,16,17,18,19,20
C. 1,2,3,4,5,6,7,8,9
D. 10,11,12,13,14,15,16,17,18,19
A. std::xvalue(x)
B. std::move(x)
C. std::shift(x)
D. std::destroy(x)
A. 0,1,2,3,4,5,6,7,8,9
B. 9,8,7,6,5,4,3,2,1
C. std::partition() doesn't work with plain arrays.
D. 9,1,7,3,5,4,6,2,8,0
E. 0,8,2,6,4,5,3,7,1,9
A. private
B. B does not inherit access to x from A.
C. public
D. protected
A. implementation defined
B. compiler error
C. false
D. true
A. compile error: ambiguous call
B. first
C. second