1. Home
  2. MCQs by exam
  3. NTS

NTS MCQs · Page 90

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

Showing 2226–2250 of 5,604

A compound literal (int[]){1, 2, 3} appears inside a function body in C99. What is its storage duration?

  1. Register, because the literal is a constant expression folded at compile time
  2. Automatic, matching the enclosing block, so the array dies when that block exits Correct answer
  3. Static, so the array outlives the enclosing block and can safely be returned to its caller
  4. Dynamic, because the compiler reserves the array with an implicit malloc call at run time
MCQSEXAM Read explanation

int x = 5; x << 32; is compiled for a platform whose int is 32 bits wide. What is the status of that shift?

  1. Undefined behaviour, because the shift count is not less than the operand's width Correct answer
  2. Defined to yield zero, because every set bit is shifted out of the 32-bit range entirely
  3. Implementation-defined, so the compiler documents whether it wraps the count
  4. A constraint violation, so a strictly conforming compiler must reject the code
MCQSEXAM Read explanation

What goes wrong when the macro #define SQ(x) ((x)*(x)) is invoked as SQ(i++)?

  1. The extra parentheses force a temporary object, so the postfix increment is discarded
  2. The preprocessor evaluates i++ once and then passes the resulting value twice
  3. The argument is substituted twice, so i is incremented twice in one expression Correct answer
  4. The macro expands into a full statement, so it cannot legally appear inside an expression
MCQSEXAM Read explanation

A compiler must implement an enum whose enumerators fit comfortably inside a char. What does the C standard actually require of its size?

  1. Exactly one byte, chosen so the type is large enough for the largest enumerator value
  2. Exactly sizeof(int), because every enumerator is guaranteed to have type int in C
  3. Exactly sizeof(long), because enums are stored in the widest integer type
  4. An implementation-defined choice among char, signed int and unsigned int types Correct answer
MCQSEXAM Read explanation

Two struct objects hold identical member values but were filled separately. Why can memcmp on them be unreliable?

  1. Assignment performs a shallow copy, so the two structs end up sharing member storage
  2. Padding bytes may hold indeterminate values, so a byte comparison can report differences Correct answer
  3. The member-wise copy converts floating values, so bit patterns can differ in the last unit
  4. memcmp inspects only the first member of the struct, ignoring all the trailing members
MCQSEXAM Read explanation

What does the volatile qualifier actually guarantee for an object in a C program?

  1. Accesses become atomic between threads, so no torn reads or partial writes can ever occur
  2. A hardware memory barrier is inserted around each access to order it against other threads
  3. The object is placed in a memory section that hardware cannot write behind the program's back
  4. Every access written in the abstract machine is performed, so the compiler cannot cache it Correct answer
MCQSEXAM Read explanation

A variable must hold a pointer to a function taking an int and returning int. Which declaration is right, and how does it compare with the alternative?

  1. int (*fp)(int); which means exactly the same thing as int *fp(int) under the C declarator precedence rules
  2. int fp(*)(int); which places the pointer inside the parameter list rather than on the name
  3. int (*fp)(int); which declares a function pointer, unlike int *fp(int) which declares a function Correct answer
  4. int *fp(int); which declares a function pointer, while int (*fp)(int) declares a function
MCQSEXAM Read explanation

A buffer's contents must be shifted three bytes to the right inside the same array. Why is memmove required instead of memcpy?

  1. memmove handles overlap by choosing a safe copy direction, while memcpy does not Correct answer
  2. memcpy refuses overlapping ranges at run time and returns a null pointer instead
  3. memmove is needed only when the two ranges are exactly equal, not when they overlap
  4. memcpy copies through a hidden temporary buffer, so it needs twice the stack space
MCQSEXAM Read explanation

Why does the loop while (!feof(fp)) { fgets(line, n, fp); puts(line); } often print the last line twice?

  1. fgets rewinds the file when it reaches the last record, so the final line is read again
  2. feof returns true at the start of the last line, so the guard terminates far too early
  3. puts flushes the buffer twice when the final newline is missing from the file
  4. feof only becomes true after a read hits end of file, so one extra iteration runs Correct answer
MCQSEXAM Read explanation

A line is read with fgets(buf, sizeof buf, stdin). What does buf contain when the whole input line fits in the buffer?

  1. Only the characters before the newline, since the newline stays in the input stream
  2. The line including its trailing newline character, if one was present in the input Correct answer
  3. The line with the newline stripped away, because fgets always truncates at the line terminator
  4. The line with the newline replaced by a NUL plus the previous buffer contents kept
MCQSEXAM Read explanation

char dst[4]; strncpy(dst, "abcd", 4); is executed. What is the state of dst afterwards?

  1. The copy is truncated to three bytes and a NUL fills the last position of dst
  2. The call is rejected at run time and dst keeps its previous uninitialised bytes
  3. The four bytes are copied with no terminating NUL, so dst is not a valid string Correct answer
  4. Three bytes are copied and a NUL is appended, since space is always reserved
MCQSEXAM Read explanation

After longjmp returns control to the setjmp point, what is guaranteed about non-volatile automatic variables of the function that called setjmp?

  1. They keep their latest modified values because the stack frame is never touched
  2. They are reset to zero, since longjmp reinitialises the function's automatic objects
  3. Their values are indeterminate if they were modified between setjmp and longjmp Correct answer
  4. Their values are reliably restored to the values they held at the setjmp call
MCQSEXAM Read explanation

Given uint8_t a = 200, b = 100; what is the type and value of the expression a + b in a typical C implementation?

  1. uint8_t with value 44, because the sum wraps at 256 and is truncated back down
  2. unsigned int with value 300, because uint8_t promotes to unsigned int on all targets
  3. int with value 44, because the sum is computed in 8 bits and then sign-extended up
  4. int with value 300, because both operands are promoted to int before the addition Correct answer
MCQSEXAM Read explanation

In C99 and later, the expression -7 % 3 is evaluated. What value results, and which rule fixes it?

  1. 2, because the remainder operator always normalises the result to a non-negative value
  2. -2, because the quotient is floored downward, which shifts the remainder in the negative direction
  3. 1, because the sign of a remainder is taken from the divisor rather than from the dividend
  4. -1, because division truncates toward zero, so the remainder keeps the dividend's sign Correct answer
MCQSEXAM Read explanation

A soil has an electrical conductivity of 6 dS/m, a sodium adsorption ratio of 8 and a pH of 8.2. How should it be classified?

  1. Saline-sodic, needing only gypsum and no drainage, since the salts will leach out in the monsoon
  2. Sodic, and it should be reclaimed with gypsum and a rice crop in the rotation
  3. Normal, needing no treatment beyond the usual fertiliser and a light irrigation
  4. Saline, and it should be reclaimed by leaching with good-quality water and drainage Correct answer
MCQSEXAM Read explanation

Which feature best distinguishes powdery mildew from downy mildew?

  1. Powdery mildew develops on the upper leaf surface in dry, humid air, while downy mildew needs free water and appears mainly on the underside Correct answer
  2. Powdery mildew affects only roots and downy mildew only fruits, so the two diseases never appear on the same plant at the same time
  3. Both are controlled only by insecticides, since neither pathogen responds to sulphur or copper fungicides at any stage of the crop cycle
  4. Powdery mildew is caused by a bacterium and downy mildew by a virus, so only the first responds to antibiotics and to the copper sprays used in the orchard
MCQSEXAM Read explanation

How does Bt cotton kill susceptible bollworm larvae?

  1. The toxin blocks the insect nervous system like a pyrethroid and paralyses the larva quickly
  2. The plant produces a fungicide that prevents spore germination on the leaf surface and in the whorl of the plant
  3. The toxin prevents moulting by inhibiting chitin synthesis in the cuticle of the developing larva
  4. Cry protein is activated in the alkaline gut and binds midgut receptors, forming pores that cause septicaemia Correct answer
MCQSEXAM Read explanation

Fall armyworm damage in maize is recognised by...

  1. ragged holes and moist frass in the whorl, with larvae showing an inverted Y on the head Correct answer
  2. root galls caused by soil insects that feed below the crown of the plant and roots
  3. circular holes in stored grain only, with no damage to the standing crop or the cobs
  4. yellowing along leaf veins without feeding damage and with healthy larvae absent from the whorl
MCQSEXAM Read explanation