- Home
- Subjects
- Computer Science MCQs
Computer Science MCQs · Page 4
992 multiple choice questions with answers across 24 topics.
-
A
The role issues an encrypted access key that is written to the instance's root volume at boot
-
B
The role removes the need for any permission policy at all, since the instance identity is trusted by default
-
C
The role lets the instance share one access key with other accounts without extra configuration
-
D
The role issues short-lived credentials through instance metadata, so no long-term secret is stored
Correct answer
-
A
Both exceptions are merged into a std::nested_exception and rethrown together
-
B
The program continues normally, with the destructor's exception silently discarded
-
C
std::terminate is called, because two active exceptions cannot propagate at once
Correct answer
-
D
The new exception replaces the old one and unwinding continues from that point
-
A
The value m.begin(), because erasing resets all stored iterators
-
B
The iterator to the following element, which erase returned by value
Correct answer
-
C
An invalidated iterator, so incrementing it afterwards is undefined behaviour
-
D
The iterator to the erased element, which remains allocated but detached
-
A
Direct-initialisation, so objects can only be created through a factory function
-
B
Copy construction, so the type can no longer be stored inside standard containers
-
C
Aggregate initialisation, since the class is no longer an aggregate after the change
-
D
Implicit conversion from the argument type at call sites and in copy-initialisation
Correct answer
-
A
It reads a valid value, because std::function extends the lifetime of captures
-
B
It reads a dangling reference, because the local died with its stack frame
Correct answer
-
C
It reads the value the local held, because capture by reference copies on escape
-
D
It throws std::bad_function_call, since the captured reference has expired
-
A
Function templates are chosen by overload resolution, so partial ordering fills that role
Correct answer
-
B
Partial specialisation of function templates was removed by the C++11 standard revision
-
C
A function template needs a class template wrapper before it can be specialised at all
-
D
Partial specialisation is allowed, but only when every template parameter is a reference type
-
A
References and pointers to elements stay valid, but the iterators are invalidated
Correct answer
-
B
Nothing survives: all iterators, pointers and references are invalidated at once
-
C
Only iterators survive, because buckets are relinked while the nodes are reallocated
-
D
Everything survives, since rehashing only changes the size of the bucket array
-
A
It fails to compile, because delete cannot be applied to an array new expression
-
B
The form of delete does not match the form of new, so the behaviour is undefined
Correct answer
-
C
Only the first element is destroyed and the remaining nine are leaked silently
-
D
The delete is acceptable, but the ten ints stay allocated until the program exits
-
A
Cast away const, which is well defined even for an actually const object
-
B
Mark the member function constexpr, since constant evaluation permits such writes
-
C
Mark the member mutable, so that a const member function can still modify it
Correct answer
-
D
Mark the member static, because const-qualification then no longer applies to it
-
A
The capture is moved to the heap once and shared between copies, making copies cheap
-
B
std::function rejects capturing lambdas, so the code fails to compile
-
C
The closure object lives inside f, so copying f copies the whole captured array
Correct answer
-
D
The lambda decays to a plain function pointer, so the captured array is not kept alive
-
A
It depends on the compiler, since merging of virtual bases is left implementation-defined
-
B
Exactly one, shared by both paths, because virtual bases are merged into one subobject
Correct answer
-
C
Two, one reached through B1 and one through B2, addressed by distinct base offsets
-
D
Zero, because virtual inheritance removes the base class entirely from the layout
-
A
shared_ptr detects cycles and defers destruction to the next garbage collection
-
B
The control blocks are leaked first, so the destructors run but the memory does not
-
C
Each object's reference count stays at one because of the mutual strong references
Correct answer
-
D
The reference counts are merged into a single counter, so they never reach zero
-
A
Value semantics and a size() member, while the elements stay contiguous in memory
Correct answer
-
B
Heap allocation, so very large arrays do not consume space in the caller's stack frame
-
C
Automatic bounds checking on every operator[] access in all build configurations
-
D
Dynamic resizing, so extra elements can be appended after the object is constructed
-
A
std::sort needs a function pointer, so a lambda cannot be used as the predicate
-
B
The predicate is fine, but it makes std::sort fall back to a stable bubble sort
-
C
The predicate is not a strict weak ordering, so the sort behaviour is undefined
Correct answer
-
D
The predicate sorts descending, which std::sort rejects with a compile error
-
A
int and int, because parentheses are ignored entirely by the decltype specifier
-
B
int& and int&, because decltype always adds a reference to any named variable
-
C
int and int&, because a parenthesised lvalue expression produces a reference type
Correct answer
-
D
int& and int, because the extra pair of parentheses strips the reference from the type
-
A
It becomes a reference to a default-constructed int placed in the new buffer
-
B
It dangles, because growth allocates a new buffer and destroys the old elements
Correct answer
-
C
It remains valid, since vector guarantees reference stability across insertions
-
D
It is rebound automatically to the new buffer at the same logical index position
-
A
emplace_back is only valid for trivially copyable types such as int and double values
-
B
The two calls are identical in every respect, including the number of constructions
-
C
emplace_back builds the string in place from the literal, push_back moves a temporary in
Correct answer
-
D
emplace_back copies an already-built string object, while push_back builds one from the literal
-
A
sv keeps the temporary alive by extending its lifetime, exactly like const& binding
-
B
sv refers to a temporary destroyed at the end of the full expression, so it dangles
Correct answer
-
C
sv owns its own copy of the characters, so the member wastes memory but stays valid
-
D
sv is rejected at compile time, because a view cannot bind to a temporary string
-
A
vector then moves elements instead of copying them, which keeps the strong guarantee
Correct answer
-
B
vector refuses to grow the buffer at all once the move constructor is declared noexcept
-
C
vector starts using memcpy on the elements, since noexcept proves they are trivial
-
D
vector falls back to copying, because noexcept disables the move constructor entirely
-
A
The move constructor, because std::move casts its argument to an rvalue reference
-
B
A compile-time error, because std::move is deleted for const-qualified arguments by design
-
C
The move constructor, because const objects are always treated as expiring values here
-
D
The copy constructor, because std::move yields a const rvalue that cannot bind to T&&
Correct answer
-
A
a is const int& and b is const int&, because auto copies the initialiser's type exactly
-
B
a is int and b is int, because auto& also drops the const qualifier from the referent
-
C
a is const int and b is const int&, because auto keeps const but removes the reference
-
D
a is int and b is const int&, because plain auto strips references and top-level const
Correct answer
-
A
-4 to 3, because a three-bit field is treated as signed unless unsigned is repeated
-
B
0 to 7, with 8 stored as 0 because the value is kept modulo 8 by the field
Correct answer
-
C
0 to 7, with 8 raising a run-time overflow trap on conforming implementations
-
D
0 to 255, because bit-fields are always widened to a full byte when stored
-
A
b only, because the matching case block ends automatically at the next label
-
B
a, b and c, because every case label above the match is also evaluated in sequence
-
C
Nothing, because no case matches once the fall-through behaviour is detected
-
D
b then c, because execution continues into the later labels without any break
Correct answer
-
A
Because the increment operator is not defined for any pointer type in the language
-
B
Because a cast to char * is needed before assigning any value to a void pointer
-
C
Because pointer arithmetic needs a complete object type to know the element size
Correct answer
-
D
Because void pointers may only be compared and never assigned a fresh address
-
A
Inline functions may not appear in shared headers, because each unit expands its own copy
-
B
The compiler inlines both copies and thereby creates two symbols with the same name
-
C
C99 requires inline functions to be static, and the header omits the static keyword
-
D
An inline definition is not an external definition, so no unit emits a callable body
Correct answer