- Home
- MCQs by exam
- NTS
NTS MCQs · Page 64
5,604 multiple choice questions typical of the NTS exam, with answers and explanations. Switch on practice mode to test yourself first.
-
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
-
A
Undefined behaviour, because free needs the pointer that malloc returned
Correct answer
-
B
Only the memory beyond p is released, and the earlier part stays allocated
-
C
The call is legal and releases the whole block through the allocation header
-
D
A diagnostic is guaranteed, since free can detect an interior pointer
-
A
offsetof is undefined for any member of a packed structure or union
-
B
The macro requires a union, and bit-fields may appear only inside structs
-
C
Bit-fields need not start on a byte boundary, so no byte offset exists
Correct answer
-
D
Bit-fields are not members of a structure and have no declared name
-
A
Nothing; a successful call always leaves errno set back to zero
-
B
Call clearerr first, since errno is only defined for stream functions
-
C
Nothing; errno is only meaningful when the function returns -1 or NULL
-
D
Set errno to 0 beforehand, because success never clears it by itself
Correct answer
-
A
Only the last registered handler h3 runs when main returns normally
-
B
h3, then h2, then h1, since handlers run in reverse registration order
Correct answer
-
C
h1, then h2, then h3, since handlers run in registration order exactly
-
D
The order is unspecified, so any permutation of the three is conforming
-
A
They keep their original relative order, since qsort is a stable sort
-
B
Their order is reversed, because qsort always swaps equal elements
-
C
Their order stays unspecified unless the comparator breaks the tie itself
-
D
Nothing is guaranteed, because qsort is not required to be stable at all
Correct answer
-
A
It is not reentrant because it calls malloc internally on the first call
-
B
It keeps the scan position in static storage shared between all calls
Correct answer
-
C
It writes into the source string, so two sources would overwrite each other
-
D
It returns pointers into a single static buffer reused on every call