- Home
- MCQs by exam
- 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.
-
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
-
A
n equals 10, but buf is left holding all ten characters without a terminator
-
B
n equals -1, because the output was truncated by the size argument given
-
C
n equals 10, and buf holds the first seven characters plus a terminator
Correct answer
-
D
n equals 7, and buf holds exactly the seven characters that it kept
-
A
Because goto may not cross any declaration that has an initialiser
-
B
It is rejected only when n is a compile-time constant expression
-
C
Jumping into the scope of a variably modified object is not permitted
Correct answer
-
D
The jump is legal, but the array a stays uninitialised until it is used
-
A
The typedef makes both a and b pointers; the macro makes only a pointer
Correct answer
-
B
Both forms declare two pointers, since the tokens are expanded identically
-
C
The typedef makes both ints, while the macro makes a pointer and an int
-
D
The macro form is a constraint violation and does not compile in C
-
A
Both shifts on negative values are undefined behaviour in standard C
-
B
Both shifts are well defined and act on the two's complement bit pattern
-
C
Left shift of a negative is implementation-defined, but right shift is undefined
-
D
Left shift of a negative is undefined; right shift is implementation-defined
Correct answer
-
A
g() always runs first, because the arguments are evaluated right to left
-
B
Nothing; the calls are indeterminately sequenced, so either order can occur
Correct answer
-
C
f() always runs first, since it appears leftmost in the argument list
-
D
The program has undefined behaviour, because one global object is written twice