1. Home
  2. MCQs by exam
  3. NTS

NTS MCQs · Page 113

5,604 multiple choice questions typical of the NTS exam, with answers and explanations. Switch on practice mode to test yourself first.

Showing 2801–2825 of 5,604

Since late 2020, what consistency does Amazon S3 provide for writes of new objects, for overwrites and for listings?

  1. Strong consistency only in the us-east-1 region, with eventual consistency in every other region
  2. Strong read-after-write consistency for PUTs of new objects and overwrites, and for list operations Correct answer
  3. Eventual consistency for all operations, with no listing guarantee and no overwrite guarantee
  4. Eventual consistency for overwrites only, with strong consistency everywhere else in the whole service
MCQSEXAM Read explanation

Which statement correctly contrasts vertical and horizontal scaling for a web tier?

  1. Both require application changes, since neither approach affects the instance count or the load balancer configuration at all
  2. Vertical scaling enlarges one instance and often needs a restart, while horizontal scaling adds instances and requires statelessness or load balancing Correct answer
  3. Vertical scaling adds more instances to the tier, while horizontal scaling enlarges the instance type, so the two terms are very often swapped in practice
  4. Horizontal scaling is limited by the largest instance size that the provider offers, so it cannot grow beyond a single machine without sharding
MCQSEXAM Read explanation

Which description correctly distinguishes an availability zone from a region?

  1. An availability zone is one or more discrete data centres with independent power and cooling inside a region, while a region is a geographic area containing several zones Correct answer
  2. An availability zone spans multiple countries and contains many regions, while a region is a single data centre with redundant power, cooling and networking of its own
  3. A region is one data centre with all of its racks, and an availability zone is a subset of those racks inside it, so the two terms describe the same facility at different scales
  4. An availability zone is a billing boundary that groups accounts, while a region is a network boundary that groups several of those billing boundaries together
MCQSEXAM Read explanation

A team runs its own database on an IaaS virtual machine. Who is responsible for applying guest operating system security patches?

  1. Neither, because patching is automated by the hypervisor at every boot of the guest
  2. The provider, because it owns the physical hosts and the hypervisor that sits beneath them
  3. The customer, because in IaaS the provider stops at the hypervisor and virtual hardware Correct answer
  4. Both equally, under a default that splits patching by kernel version and by machine image
MCQSEXAM Read explanation

Base declares virtual void f(int x = 10); and Derived overrides it as void f(int x = 20);. Through a Base* b pointing at a Derived object, b->f() passes which argument?

  1. The call is ambiguous and fails to compile, because the two declarations disagree about the default argument values used
  2. 20, because the dynamic type of the object is Derived and its own default arguments apply to the call in full
  3. 10, because default arguments are bound statically from the pointer's type while the override is chosen dynamically Correct answer
  4. 10 or 20 depending on the compiler, since the standard leaves the choice of default arguments unspecified here
MCQSEXAM Read explanation

An object is defined as const int c = 10; and const_cast is used to write through a pointer to it. What is the result?

  1. A compile error is guaranteed on every conforming compiler, because const_cast is rejected there
  2. Undefined behaviour, because modifying an object that is genuinely const is not allowed Correct answer
  3. It works and c becomes the new value, because the pointer overrides the const qualifier
  4. It is well defined, but the write is silently discarded, so c keeps its original value of 10
MCQSEXAM Read explanation

Which of these operators cannot be overloaded in C++?

  1. operator++ and operator--, in prefix or postfix form, cannot be overloaded
  2. The conditional operator ?: together with ::, . (member access), .* and sizeof Correct answer
  3. operator[] and operator(), although both are member functions with arguments and return values
  4. operator new and operator delete, in either their throwing or their non-throwing forms
MCQSEXAM Read explanation

Which is the accurate comparison of std::map and std::unordered_map?

  1. map keeps keys ordered with O(log n) operations; unordered_map gives average O(1) with no ordering and O(n) worst case Correct answer
  2. Both keep the keys ordered, differing only in hash quality, so iteration order is identical for both of the two containers
  3. unordered_map iterates in insertion order, unlike map, which re-sorts the keys at every single insertion
  4. map gives O(1) lookup while unordered_map is O(log n), because a balanced tree always beats a hash table
MCQSEXAM Read explanation

Before C++17, a static const int member with an in-class initialiser still required what, if it was odr-used?

  1. A second declaration inside main, because the initialiser was not visible outside the class scope
  2. An out-of-class definition, because the in-class initialiser served only as a declaration for such uses Correct answer
  3. A definition in every translation unit that included the header, to satisfy the one-definition rule
  4. Nothing, since in-class initialisers always provided a full definition that the linker was normally able to use
MCQSEXAM Read explanation

Which does new T provide that malloc(sizeof(T)) does not?

  1. It returns memory aligned to at least 4096 bytes, which malloc is not required to guarantee for any type
  2. It zero-initialises the object unless a constructor sets fields, which malloc never does for any type
  3. It can allocate arrays, whereas malloc cannot, because malloc knows nothing about element counts
  4. It runs T's constructor and reports failure by throwing std::bad_alloc instead of returning null Correct answer
MCQSEXAM Read explanation

Which statement about std::unique_ptr is correct?

  1. It is copyable, and copying it duplicates the object with a fresh allocation
  2. It is move-only: copying is deleted, and ownership is transferred with std::move Correct answer
  3. It may be copied, but both pointers then share ownership through a hidden reference count
  4. It requires a reference count stored in a control block allocated beside the managed object
MCQSEXAM Read explanation

Base's constructor calls a virtual function that Derived overrides, and a Derived object is being constructed. Which version runs?

  1. The program fails to compile, because virtual calls in constructors are illegal and are always rejected by every conforming compiler
  2. Derived's version, because the dynamic type of the object is already Derived from the moment the allocation completes
  3. Base's version, because during base construction the vptr still refers to Base's vtable and the Derived part does not yet exist Correct answer
  4. It is undefined behaviour, so either version may run depending on the compiler and on the optimisation level used
MCQSEXAM Read explanation

Why is the override specifier preferred on a derived virtual function?

  1. It turns a would-be silent non-override, such as a missing const or a wrong parameter type, into a compile error Correct answer
  2. It allows the function to be inlined by the compiler, because the exact target is known at compile time
  3. It forces the base function to become virtual for the first time, even when the base declares it non-virtual
  4. It makes the function callable through a base pointer, which is otherwise impossible for a derived member function
MCQSEXAM Read explanation

Given a std::map<std::string, int> named counts, what happens when counts['alpha'] is evaluated for a key that is not present?

  1. A new element with a value-initialised int of 0 is inserted, so a lookup silently grows the map Correct answer
  2. std::out_of_range is thrown, exactly as counts.at('alpha') would throw for a missing key
  3. A reference to a shared static zero is returned and the map itself is left unmodified
  4. An iterator to the end of the map is returned, and dereferencing it is undefined behaviour
MCQSEXAM Read explanation

void f(Base b); is called as f(derivedObject); where Derived publicly derives from Base and both override a virtual print(). What does b.print() call inside f?

  1. Base::print, because object slicing copies only the Base sub-object into the parameter Correct answer
  2. It is undefined behaviour, so either version may run depending on the optimisation level
  3. Derived::print, because the argument's dynamic type stays Derived inside the function
  4. Derived::print if Base's destructor is virtual, else Base::print, since dispatch depends on it
MCQSEXAM Read explanation

For objects a and b of class T, which special member is used by T b = a; and which by b = a; when b already exists?

  1. Copy-initialisation uses the copy constructor; assignment to an existing object uses the copy assignment operator Correct answer
  2. Both use the copy constructor, since the equals sign always means construction even for a live object
  3. Both use the copy assignment operator, since the equals sign always means assignment whatever the surrounding context
  4. T b = a; uses the default constructor followed by assignment, because b is an already constructed object
MCQSEXAM Read explanation

On an empty std::vector<int> v, what do v.reserve(100) and v.resize(100) each produce?

  1. Both set only capacity, differing solely in the exception guarantees offered when a reallocation fails
  2. reserve sets capacity to 100 with size still 0; resize sets size and capacity to 100 with value-initialised elements Correct answer
  3. Both set size to 100, but reserve leaves the new elements uninitialised until each element is written
  4. reserve sets size to 100 and resize only sets capacity, so writing v[0] directly after reserve is perfectly well defined
MCQSEXAM Read explanation

class D : public A, public B { Mem1 m1; Mem2 m2; public: D() : m2(2), m1(1), B(), A() {} }; In what order are bases and members initialised, and destroyed?

  1. m2, m1, B, A for initialisation, matching the initialiser list
  2. m1, m2, A, B for initialisation and A, B, m1, m2 for destruction
  3. A, B, m1, m2 for initialisation and the same order for destruction
  4. A, B, m1, m2 for initialisation and m2, m1, B, A for destruction Correct answer
MCQSEXAM Read explanation

class B { public: ~B() {} }; class D : public B { public: ~D() {} }; and then delete (B*)new D; is executed. What happens?

  1. Only D's destructor runs, because the dynamic type is D
  2. Undefined behaviour: only B's destructor runs, because B's destructor is not virtual Correct answer
  3. Both destructors run, since destructors are always virtual
  4. A compile error, because a base pointer cannot delete a derived object
MCQSEXAM Read explanation