- Home
- MCQs by exam
- NTS
- Computer Science MCQs
NTS MCQs – Computer Science MCQs · Page 2
455 multiple choice questions typical of the NTS exam, with answers and explanations. Switch on practice mode to test yourself first.
-
A
It has static storage duration, so returning the list by value is safe
-
B
It ends with the full-expression that created it, like any temporary array
Correct answer
-
C
It ends only with the enclosing block, exactly as a local const array does
-
D
It lasts as long as the initializer_list object that was copied from it
-
A
Compiles and sets x to 3, since braced init truncates like a cast does
-
B
Compiles and sets x to 4, since braced init rounds to the nearest integer
-
C
Compiles with a warning, since the value is implementation-defined here
-
D
Rejects it, because narrowing conversions are ill-formed in braced init
Correct answer
-
A
It performs one allocation for both the object and the control block
Correct answer
-
B
It performs two allocations but avoids any virtual dispatch
-
C
It keeps the control block on the stack, so only the object is heap based
-
D
It uses a separate allocator, so the object and control block never free
-
A
Predicates are evaluated outside the lock, so the result may become stale
-
B
Wake-ups can occur without a notify, so the condition must be rechecked
Correct answer
-
C
The mutex is released before the predicate runs and may be reacquired late
-
D
notify_one can be lost when nobody is waiting, so the wait must poll
-
A
Atomicity only for threads that happen to share the same cache line layout
-
B
Atomicity of the operation only, with no ordering against other accesses
Correct answer
-
C
Atomicity plus release ordering of every preceding write in that thread
-
D
Atomicity plus sequential consistency with respect to all other atomics
-
A
The object is built directly in the caller's storage, with no move at all
Correct answer
-
B
One move construction happens, but the copy constructor is elided
-
C
The move constructor must still be accessible even though it is never called
-
D
The compiler may elide the move, but this remains optional for it
-
A
int&, because the forwarding reference collapses to an lvalue reference
Correct answer
-
B
int, because the reference in the parameter is stripped before deduction
-
C
int&&, because the parameter is declared as an rvalue reference to T
-
D
const int&, because lvalues are deduced as const in template deduction
-
A
The first element equal to the value, found by a linear scan fallback
-
B
A compilation error, since the predicate cannot be checked in advance
-
C
Undefined behaviour, because the range must be partitioned for the search
Correct answer
-
D
Unspecified behaviour; the algorithm still returns some element of the range
-
A
int, because the standard requires accumulate to work integrally
-
B
int, because the accumulator takes the type of the initial value given
Correct answer
-
C
double, because it converts the seed to the range's value type
-
D
double, since the accumulation widens to the element type of the range
-
A
All iterators are invalidated, because the tree rebalances its nodes
-
B
Iterators to later elements are invalidated, while earlier ones stay valid
-
C
Iterators become valid again after the next insert into the container
-
D
Only the erased iterator is invalidated; every other iterator stays valid
Correct answer
-
A
The subscript returns an rvalue reference that cannot bind to auto&
-
B
A vector of bool has no operator[] because it is not a container
-
C
operator[] yields a proxy object by value, not a real bool reference
Correct answer
-
D
vector of bool packs bits, so its elements are const and cannot bind
-
A
A floating-point type such as double, which has no integer promotions
Correct answer
-
B
An unsigned long long, because the case labels would overflow int
-
C
A plain char, because its signedness is implementation-defined in C
-
D
An enumerated type, because its enumerators are not integer constants
-
A
sizeof yields size_t, so the subtraction is unsigned and wraps to a huge value
Correct answer
-
B
The expression is evaluated at run time, so the compiler cannot fold it at all
-
C
int is signed, so the subtraction borrows and produces a negative value
-
D
The comparison is always true because sizeof(int) alone exceeds zero here
-
A
a is a local copy of ten elements, so writes inside f do not escape
-
B
a may be a null pointer whenever fewer than ten elements are supplied here
-
C
a points to at least 10 elements, allowing more aggressive code generation
Correct answer
-
D
a must hold exactly ten elements, and longer arrays are not permitted
-
A
Twice, because it expands to a[i++] = a[i++] + 10 in the abstract machine here
-
B
Zero times until the addition completes, since the store is sequenced last
-
C
Undefined, because the operand is modified and read in the same expression
-
D
Once, because a compound assignment evaluates its left operand a single time
Correct answer
-
A
The first is a constraint violation, because C requires a parameter list
-
B
The first permits exactly one argument of any type, like an old-style call
-
C
The first declares no prototype, so any arguments are accepted unchecked
Correct answer
-
D
Both declare a function taking no arguments and behave identically
-
A
6, because the literals share one terminator between them
-
B
9, because a separator character is inserted between the two literals
-
C
7, because adjacent literals are concatenated before compilation
Correct answer
-
D
8, because each literal keeps its own terminating null character
-
A
0, because reaching the end of main is equivalent to returning zero
Correct answer
-
B
An indeterminate value, because no return expression was ever evaluated
-
C
1, because falling off the end of main is treated as abnormal termination
-
D
The value is implementation-defined and must be read from the shell
-
A
It is a constraint violation, so a conforming compiler must diagnose it
Correct answer
-
B
It is the size of the code generated for the function, a few dozen bytes
-
C
It is the size of a function pointer on that platform, typically 8 bytes
-
D
It is 1, like sizeof(void), because functions are incomplete types in C
-
A
It only works when the header is included with angle brackets, not quotes
-
B
It prevents duplicate inclusion only inside a single translation unit
-
C
It is non-standard, so a compiler may ignore it and reprocess the header
Correct answer
-
D
It is standard since C99, but older preprocessors treat it as a comment
-
A
At run time, giving n times the element size, with no compile-time constant
Correct answer
-
B
At compile time, giving the maximum size the array could possibly take
-
C
At run time, giving the address of the last element instead of a byte size value
-
D
At compile time, giving the size of a pointer because a is an array name
-
A
Undefined behaviour, because fp is an indeterminate pointer after fclose
Correct answer
-
B
It returns EOF, since the stream remembers that it has been closed
-
C
It is legal and reopens the file automatically in read mode for you
-
D
It returns EOF only if the stream had reached end-of-file before closing
-
A
It wraps the product modulo SIZE_MAX and allocates that size
-
B
It aborts the process, because calloc treats overflow as a fatal error
-
C
Nothing; overflow is undefined behaviour that the caller must prevent
-
D
It fails and returns a null pointer instead of an undersized block
Correct answer
-
A
It is undefined behaviour, since realloc is never permitted a zero size at all
-
B
Implementation-defined: it may free p and return NULL, or return a small block
Correct answer
-
C
It always frees p and returns NULL, which the caller must then not free again
-
D
It always returns NULL and leaves the original block p unchanged and valid
-
A
Floats are converted to int in a variadic call, so ask for an int
-
B
va_arg may only take pointer types, so an explicit cast is required first
-
C
va_arg may only take pointer types, so an explicit cast is required before use
-
D
Default argument promotions pass it as double, so va_arg must ask for double
Correct answer