1. Home
  2. MCQs by exam
  3. PPSC IT

PPSC IT MCQs · Page 4

577 multiple choice questions typical of the PPSC IT exam, with answers and explanations. Switch on practice mode to test yourself first.

Showing 76–100 of 577

Which type may a switch statement's controlling expression NOT have in C?

  1. A floating-point type such as double, which has no integer promotions Correct answer
  2. An unsigned long long, because the case labels would overflow int
  3. A plain char, because its signedness is implementation-defined in C
  4. An enumerated type, because its enumerators are not integer constants
MCQSEXAM Read explanation

const char s[] = "abcdef"; is written as two adjacent literals, "abc" and "def". How many characters does the array hold, including the terminator?

  1. 6, because the literals share one terminator between them
  2. 9, because a separator character is inserted between the two literals
  3. 7, because adjacent literals are concatenated before compilation Correct answer
  4. 8, because each literal keeps its own terminating null character
MCQSEXAM Read explanation

int a[n]; is declared inside a function, with n supplied at run time. When is sizeof(a) evaluated, and what does it yield?

  1. At run time, giving n times the element size, with no compile-time constant Correct answer
  2. At compile time, giving the maximum size the array could possibly take
  3. At run time, giving the address of the last element instead of a byte size value
  4. At compile time, giving the size of a pointer because a is an array name
MCQSEXAM Read explanation

calloc(nmemb, size) must allocate nmemb times size bytes. What does the standard additionally guarantee about that multiplication?

  1. It wraps the product modulo SIZE_MAX and allocates that size
  2. It aborts the process, because calloc treats overflow as a fatal error
  3. Nothing; overflow is undefined behaviour that the caller must prevent
  4. It fails and returns a null pointer instead of an undersized block Correct answer
MCQSEXAM Read explanation

p points to the third element of a block obtained from malloc. What happens if the program calls free(p)?

  1. Undefined behaviour, because free needs the pointer that malloc returned Correct answer
  2. Only the memory beyond p is released, and the earlier part stays allocated
  3. The call is legal and releases the whole block through the allocation header
  4. A diagnostic is guaranteed, since free can detect an interior pointer
MCQSEXAM Read explanation

Three handlers are registered with atexit in the order h1, h2, h3, and then main returns normally. In what order do the handlers run?

  1. Only the last registered handler h3 runs when main returns normally
  2. h3, then h2, then h1, since handlers run in reverse registration order Correct answer
  3. h1, then h2, then h3, since handlers run in registration order exactly
  4. The order is unspecified, so any permutation of the three is conforming
MCQSEXAM Read explanation

Two records compare equal under a qsort comparator. What does the C standard guarantee about their relative order after sorting?

  1. They keep their original relative order, since qsort is a stable sort
  2. Their order is reversed, because qsort always swaps equal elements
  3. Their order stays unspecified unless the comparator breaks the tie itself
  4. Nothing is guaranteed, because qsort is not required to be stable at all Correct answer
MCQSEXAM Read explanation

A goto statement jumps forward over the declaration int a[n]; inside the same block. Why does a conforming C compiler reject this?

  1. Because goto may not cross any declaration that has an initialiser
  2. It is rejected only when n is a compile-time constant expression
  3. Jumping into the scope of a variably modified object is not permitted Correct answer
  4. The jump is legal, but the array a stays uninitialised until it is used
MCQSEXAM Read explanation

Given typedef int *intptr; the declaration intptr a, b; differs from a #define of intptr for int * in which respect?

  1. The typedef makes both a and b pointers; the macro makes only a pointer Correct answer
  2. Both forms declare two pointers, since the tokens are expanded identically
  3. The typedef makes both ints, while the macro makes a pointer and an int
  4. The macro form is a constraint violation and does not compile in C
MCQSEXAM Read explanation

A program shifts a negative int value both left (x << 1) and right (x >> 1). Under the C standard, how are the two operations classified?

  1. Both shifts on negative values are undefined behaviour in standard C
  2. Both shifts are well defined and act on the two's complement bit pattern
  3. Left shift of a negative is implementation-defined, but right shift is undefined
  4. Left shift of a negative is undefined; right shift is implementation-defined Correct answer
MCQSEXAM Read explanation

Both f() and g() are passed to printf as arguments and each increments the same global counter. What does standard C guarantee about the values printed?

  1. g() always runs first, because the arguments are evaluated right to left
  2. Nothing; the calls are indeterminately sequenced, so either order can occur Correct answer
  3. f() always runs first, since it appears leftmost in the argument list
  4. The program has undefined behaviour, because one global object is written twice
MCQSEXAM Read explanation