100 C Programming MCQs with Answers and Explanations

These C programming MCQs contain exactly 100 questions, ten in each of ten topic groups. The baseline is C17; questions about a specific library, tool or target say so. Every question has one best answer and an explanation. This is a study quiz, not a timed assessment or certification.

A C programming quiz shows four choices, a checked answer, and one hundred questions.

Jump to the 100-question practice quiz. Choose answers using native radio buttons, then select Check score. Unanswered questions count as incorrect in the total but are reported separately. Answers can be expanded at any time for study. Changing an answer clears the old score until you check again. Reset quiz clears selections and returns focus to the first question. Selections stay only in this page’s memory and are lost on reload; no login or server storage is used.

Topics and study order

Group Questions
Fundamentals 1–10
Types and conversions 11–20
Expressions and control flow 21–30
Functions and storage 31–40
Arrays and strings 41–50
Pointers and allocation 51–60
Structures and preprocessing 61–70
Input, files and debugging 71–80
Algorithms and complexity 81–90
Bits, concurrency and portability 91–100

Without JavaScript, the full question set and expandable answers remain readable, but automatic scoring is unavailable. Tab reaches controls, arrow keys move within native radio groups, and Space selects an option or activates a focused disclosure. Avoid using one observed compiler result to justify a claim about undefined behavior.

Warm-up: predict a defined result

#include <stdio.h>
int main(void) {
    int a = 7, b = 2;
    printf("Integer division: %d\n", a / b);
    printf("Floating division: %.1f\n", (double)a / b);
    return 0;
}

Run integer and floating division online

Expected output

Reference output for the displayed program, not a live execution result.

Integer division: 3
Floating division: 3.5

The cast changes the left operand before division, producing floating-point division. Casting the result of integer division afterward would not recover the discarded fractional part. The reference output is not a live run; use the link to open the complete program.

Review after the quiz

Use 30 interview questions and lab viva practice for explanations aloud, the sorting guide for algorithm comparisons, and embedded C interviews for hardware-specific discussion. These questions have no claimed pass threshold or PDF download. Revisit missed concepts before repeating the quiz.

100-question C practice quiz

Choose one answer per question. Use Tab to reach a question, arrow keys to move between its options, and Space to select. Expand any answer for study; there is no timer.

0 / 100 answered. Check score when you are ready.

Fundamentals

1. Which hosted C17 definition clearly declares main with no parameters?
Answer and explanation for question 1

C. int main(void) — Hosted main returns int. The void parameter list explicitly specifies no parameters; identifier case matters.

2. What does #include <stdio.h> primarily make available?
Answer and explanation for question 2

C. Standard I/O declarations — Inclusion supplies header contents during preprocessing. Compilation and linking still have separate jobs.

3. What does return 0 from the initial call to main report?
Answer and explanation for question 3

D. Successful termination — Zero is a success status for hosted termination; returning it does not print a character.

4. Which delimiter ends an ordinary expression statement?
Answer and explanation for question 4

B. ; — A semicolon terminates an expression statement, although not every C construct is an expression statement.

5. Which filename extension conventionally selects C source for GCC?
Answer and explanation for question 5

A. .c — The .c extension selects C source by convention. .cpp is C++, .o is an object, and .exe is commonly an executable.

6. Which comment form is valid in C17?
Answer and explanation for question 6

C. // to the end of the line — Line comments beginning // have been part of C since C99. Block comments use slash-star and star-slash.

7. Are total and Total the same C identifier?
Answer and explanation for question 7

A. No, C identifiers are case-sensitive — Case is significant in identifiers. Choosing consistent spelling is part of declaring and using the same name.

8. Which standard header provides size_t and NULL?
Answer and explanation for question 8

A. <stddef.h> — stddef.h defines size_t and NULL, along with other common definitions. Some other standard headers also define them.

9. What is a string literal written with?
Answer and explanation for question 9

A. Double quotes — Double quotes delimit a string literal. Single quotes denote character constants, not strings.

10. What does the escape sequence \n represent in a string?
Answer and explanation for question 10

D. A newline character — The escape sequence represents a newline in the execution character set. A literal backslash needs its own escape.

Types and conversions

11. What is sizeof(char) on every conforming C implementation?
Answer and explanation for question 11

D. 1 — sizeof measures C bytes, and char occupies exactly one such byte. CHAR_BIT gives bits per byte.

12. What gives the number of bits in a C byte?
Answer and explanation for question 12

B. CHAR_BIT from limits.h — CHAR_BIT is at least 8. A C byte is not required to have exactly eight bits on every target.

13. What is the portable assumption about the width of int?
Answer and explanation for question 13

D. Its range meets the standard minimum, but its width varies — Use limits.h to inspect its range. Hardware and ABI conventions do not create a universal width.

14. How does unsigned arithmetic behave when its result exceeds the type range?
Answer and explanation for question 14

D. It is reduced modulo one more than the maximum value — Unsigned arithmetic is modular. Promotions can change the type in which an expression is evaluated.

15. What is signed integer overflow in ordinary C17 arithmetic?
Answer and explanation for question 15

B. Undefined behavior — The language does not require wrapping or a diagnostic for an unrepresentable signed arithmetic result.

16. What is the result of integer expression 7 / 2?
Answer and explanation for question 16

A. 3 — Both operands are int, so integer division discards the fractional part toward zero.

17. What is the result of -7 / 2 in C17?
Answer and explanation for question 17

A. -3 — C17 integer division truncates toward zero when the quotient is representable and the divisor is nonzero.

18. What is the type of an ordinary character constant such as 'A' in C?
Answer and explanation for question 18

D. int — Unlike a string literal, an ordinary character constant has type int in C.

19. Which printf conversion matches size_t?
Answer and explanation for question 19

A. %zu — The z length modifier with u formats size_t as an unsigned integer. Mismatched variadic argument types are unsafe.

20. What is guaranteed about uint32_t in stdint.h?
Answer and explanation for question 20

B. If provided, it is an unsigned integer type with exactly 32 bits — Exact-width typedefs are optional when the implementation lacks a type meeting the exact requirements.

Expressions and control flow

21. Which operator short-circuits when its left operand is zero?
Answer and explanation for question 21

D. && — Logical AND evaluates its right operand only when the left operand is nonzero.

22. Which operator short-circuits when its left operand is nonzero?
Answer and explanation for question 22

C. || — Logical OR does not evaluate the right operand once the left operand has established truth.

23. Which expression is a comparison rather than assignment?
Answer and explanation for question 23

A. x == 3 — Double equals compares values; a single equals assigns a value and itself yields a value.

24. Which loop executes its body at least once?
Answer and explanation for question 24

C. do ... while — A do loop checks its condition after its body, unlike while and a conventional for condition.

25. What does break exit?
Answer and explanation for question 25

D. The innermost enclosing loop or switch — break transfers control out of the nearest loop or switch, not arbitrary enclosing blocks.

26. What does continue do inside a for loop?
Answer and explanation for question 26

B. Moves to the iteration expression, then the next condition test — The iteration expression still runs after continue in a for loop, before the condition is checked again.

27. What happens after a matching switch case without break or another control transfer?
Answer and explanation for question 27

A. Execution can fall through into the next labeled statements — Case labels do not create implicit breaks. Intentional fallthrough should be clear to readers and tools.

28. Which integer values count as true in an if condition?
Answer and explanation for question 28

A. Every nonzero value — Scalar conditions test against zero; a negative integer is also true.

29. What does 1 + 2 * 3 evaluate to?
Answer and explanation for question 29

B. 7 — Multiplication binds more tightly than addition. Parentheses can explicitly choose another grouping.

30. How many operands of the conditional expression flag ? a() : b() are called?
Answer and explanation for question 30

A. Exactly one of a() and b(), depending on flag — After evaluating the condition, only the selected second or third operand is evaluated.

Functions and storage

31. How does C pass function arguments?
Answer and explanation for question 31

C. By value, including pointer values — A pointer argument is also a copied value; writes through it can still modify a caller-owned object.

32. Under C17, which declaration is a prototype for a function taking no arguments?
Answer and explanation for question 32

A. int f(void); — In C17 an empty parameter list in a declaration does not specify a no-argument prototype.

33. What happens to a block-scope static int without an explicit initializer?
Answer and explanation for question 33

C. It is initialized to zero and retains its value between calls — Static storage duration supplies default zero initialization; block scope remains local.

34. What linkage does a file-scope static function have?
Answer and explanation for question 34

A. Internal linkage — Internal linkage restricts the name to its translation unit. It does not prohibit calls within that unit.

35. What does an extern declaration usually let a source file do?
Answer and explanation for question 35

B. Refer to a compatible external definition supplied elsewhere — Compatible declarations can share an external definition, but extern does not override internal linkage.

36. When does an ordinary automatic local object’s lifetime end?
Answer and explanation for question 36

D. When execution leaves its associated block — Returning an address of such a local object leaves no live referent after the block is exited.

37. What is necessary for a terminating recursive algorithm?
Answer and explanation for question 37

B. A reachable base case and progress toward it — A base case alone is insufficient if recursive steps never reach it; resource limits still matter.

38. Which declaration makes operation a pointer to a function taking two ints and returning int?
Answer and explanation for question 38

A. int (*operation)(int, int); — Parentheses bind the pointer declarator to the function type. Without them, the first distractor declares a function returning a pointer.

39. Can a function return a struct value?
Answer and explanation for question 39

C. Yes — Returning a struct is standard C and can convey multiple named result fields in one return value.

40. What is the safest place for a shared function declaration?
Answer and explanation for question 40

C. A header included by its callers and definition — A shared header helps keep declaration and definition types consistent across translation units.

Arrays and strings

41. For int a[5], which is the last valid element index?
Answer and explanation for question 41

B. 4 — Indices begin at zero and end at count minus one. One-past pointers may exist but cannot be dereferenced.

42. Where is sizeof a / sizeof a[0] a valid element-count idiom?
Answer and explanation for question 42

C. Where a is an actual array, not an adjusted function parameter — An array parameter adjusts to a pointer, losing the whole-array size information.

43. What normally happens to an array expression passed as a function argument?
Answer and explanation for question 43

B. It converts to a pointer to its first element — Ordinary array-to-pointer conversion does not supply the length. APIs must carry that information separately.

44. What distinguishes a C string from an arbitrary char buffer?
Answer and explanation for question 44

B. A terminating null character within accessible storage — String functions rely on a reachable terminator. Capacity alone does not make a buffer a valid string.

45. What is strlen("cat")?
Answer and explanation for question 45

D. 3 — strlen counts characters before the first null terminator, not the terminator itself.

46. For char s[] = "cat", what is sizeof s?
Answer and explanation for question 46

D. 4 — The array includes c, a, t and the terminating null character; each char occupies one C byte.

47. May a program modify the characters of a string literal?
Answer and explanation for question 47

A. No, attempting to modify it is undefined behavior — Use a writable array initialized from the literal when you need mutable characters.

48. Which function compares null-terminated string contents?
Answer and explanation for question 48

C. strcmp — Pointer equality tests addresses, not character sequences. strcmp compares string contents until a difference or terminator.

49. Which standard function is designed for copying overlapping byte regions?
Answer and explanation for question 49

D. memmove — memmove supports overlap. memcpy requires the source and destination regions not to overlap.

50. What does fgets do when a newline fits and is read?
Answer and explanation for question 50

B. Stores that newline in the buffer before the terminator — Successful fgets stores at most size minus one characters and a null terminator; a read newline is retained.

Pointers and allocation

51. What does &x obtain for an ordinary addressable object x?
Answer and explanation for question 51

C. A pointer to x — The address-of operator produces a pointer. Not every expression is an addressable object, such as a bit-field.

52. What does *p do when p points to a live int object?
Answer and explanation for question 52

B. Designates the pointed-to int object — Indirection designates the referent; validity, lifetime and alignment remain preconditions.

53. What is the correct use of a one-past array pointer?
Answer and explanation for question 53

C. Use it as an iteration endpoint without dereferencing it — A one-past pointer is permitted for pointer arithmetic and comparisons under the array rules, not as an element.

54. What does const int *p restrict?
Answer and explanation for question 54

C. Modifying the int through p — The target is read-only through this pointer. Another valid alias may modify an object that was not defined const.

55. What does int * const p restrict?
Answer and explanation for question 55

C. Changing the pointer value p after initialization — The pointer object is const, not the pointed-to int.

56. What is required before reading newly malloc-allocated int elements?
Answer and explanation for question 56

D. Initialize those elements and check allocation success — malloc does not initialize the storage’s contents, and a null result must not be dereferenced.

57. What does calloc guarantee about the allocated storage?
Answer and explanation for question 57

A. All bits are initialized to zero — All-bits-zero is the guarantee, not a universal representation promise for every scalar type.

58. If realloc(p, nonzero_size) fails, what happens to the original allocation?
Answer and explanation for question 58

C. It remains allocated and unchanged — Use a temporary result so failure does not overwrite your only pointer to the still-owned allocation.

59. Which pointer can always be passed to free without releasing a live allocation?
Answer and explanation for question 59

C. NULL — free(NULL) has no effect. Invalid non-null pointers and repeated frees can cause undefined behavior.

60. What must precede malloc(count * sizeof *p) when count is untrusted?
Answer and explanation for question 60

D. A representability check on the size multiplication — Check count against SIZE_MAX / sizeof *p. Wrapped byte sizes can allocate less storage than later writes require.

Structures and preprocessing

61. What can increase sizeof a struct beyond the sum of member sizes?
Answer and explanation for question 61

B. Padding for alignment — Member and trailing padding depend on the implementation and ABI, so exact layouts need target-specific checks.

62. How is storage for members arranged in a union?
Answer and explanation for question 62

D. Members overlap, and the union is large enough for each — Union size can include alignment padding. Track the active variant rather than treating it like a struct.

63. Which operator accesses a struct member through a pointer p?
Answer and explanation for question 63

B. p->member — The arrow form is equivalent to (*p).member when p points to the appropriate struct or union object.

64. What does typedef create?
Answer and explanation for question 64

A. A type alias — typedef introduces an alias understood by the compiler; it does not allocate storage or inherently create a distinct type.

65. What is a risk of a macro that uses its argument twice?
Answer and explanation for question 65

D. An argument with side effects may be evaluated more than once — Parenthesizing a macro helps precedence but does not remove repeated evaluation.

66. What is the purpose of a conventional include guard?
Answer and explanation for question 66

D. Prevent repeated processing of the guarded header within one translation unit — An ifndef/define guard prevents repeated declarations from the same header during that preprocessing run.

67. At what stage does ordinary macro expansion occur?
Answer and explanation for question 67

C. Preprocessing — Preprocessing works on tokens before later translation stages generate the program.

68. What is a useful alternative to a function-like macro for single evaluation?
Answer and explanation for question 68

B. An ordinary or static inline function with suitable parameter types — Function arguments are evaluated once per argument occurrence at the call site, avoiding a macro body’s repeated expansion.

69. What does offsetof from stddef.h report for an eligible struct member?
Answer and explanation for question 69

A. Its byte offset within the structure — offsetof reports a layout offset. Bit-fields and invalid member designators are not arbitrary safe operands.

70. Why is writing a raw struct directly as a portable file format risky?
Answer and explanation for question 70

D. Padding, widths, byte order and representation can differ — Define an explicit external encoding rather than assuming one target’s in-memory ABI is a portable format.

Input, files and debugging

71. What does a successful scanf("%d", &x) return?
Answer and explanation for question 71

B. 1 — The return value counts successful conversions, not the input number itself.

72. What can scanf return when input failure occurs before the first conversion?
Answer and explanation for question 72

D. EOF — EOF indicates input failure before a conversion; a matching failure can instead return zero.

73. Why retain fgetc results in int until checking EOF on ordinary targets?
Answer and explanation for question 73

A. To retain the returned character value or EOF indicator — Converting to char too early can conflate an input character with the end-of-file indicator.

74. What should you check after a file-reading loop ends?
Answer and explanation for question 74

B. ferror to distinguish a read error from ordinary end-of-file — An EOF return can accompany a read failure. End-of-file is not the only reason a loop stops.

75. What does fopen return on failure?
Answer and explanation for question 75

A. A null pointer — Check the returned FILE pointer before using stream operations.

76. What normally happens to an existing file opened successfully with mode "w"?
Answer and explanation for question 76

D. It is truncated — The w mode creates or truncates for writing. Use a suitable mode and error handling to avoid unintended loss.

77. Which flags ask GCC for commonly useful warnings?
Answer and explanation for question 77

D. -Wall -Wextra -Wpedantic — These enable useful warning sets. They do not prove correctness or enable every possible warning.

78. What distinguishes a runtime error from a compilation error?
Answer and explanation for question 78

C. It occurs after a successfully built program begins running — Track whether the current source built successfully before diagnosing execution; stale binaries can confuse this distinction.

79. What is AddressSanitizer useful for on supported builds?
Answer and explanation for question 79

B. Detecting many invalid memory accesses during execution — A sanitizer is a diagnostic aid. Untested paths and unsupported issue classes still exist.

80. What should you do with a claimed output from undefined behavior?
Answer and explanation for question 80

D. Reject it as a portable prediction — One observed result does not impose a language guarantee on undefined behavior.

Algorithms and complexity

81. What is required for ordinary binary search on an array?
Answer and explanation for question 81

A. The array is sorted according to the searched ordering — Sorted order permits eliminating half the interval. Duplicate policies should be documented separately.

82. What midpoint avoids adding two potentially large bounds?
Answer and explanation for question 82

C. low + (high - low) / 2 for nonnegative, ordered array-index bounds — With nonnegative ordered array-index bounds of a suitable integer type, the difference fits and the midpoint remains inside the interval. Arbitrary signed bounds need additional range checks.

83. What is the worst-case comparison count of linear search?
Answer and explanation for question 83

C. O(n) — An absent target or last-position match can require examining every element once.

84. Which insertion-sort comparison preserves equal-key order when shifting?
Answer and explanation for question 84

C. Shift only when the earlier key is strictly greater — Not moving earlier equal keys past the inserted key preserves the relative order of equal-key records.

85. What does a swapped flag enable in optimized bubble sort?
Answer and explanation for question 85

B. An early stop after a pass with no swaps — A no-swap pass establishes that the scanned adjacent order is already sorted, giving a linear best case.

86. Is conventional swap-based selection sort stable?
Answer and explanation for question 86

B. No, distant swaps can reverse equal-key records — Selecting a minimum and swapping it across equal records can change their original relative order.

87. Which tie choice makes a conventional merge stable?
Answer and explanation for question 87

A. Take the left-half record first on equal keys — Taking the earlier half’s equal record first preserves original ordering when both halves were stably sorted.

88. What is a worst case for a simple last-pivot two-way quicksort?
Answer and explanation for question 88

B. Sorted or all-equal input can yield O(n squared) work — Highly unbalanced partitions make the recurrence quadratic. Stack-limiting transformations do not remove that work.

89. What extra array storage does conventional iterative heap sort require?
Answer and explanation for question 89

C. O(1) — An in-place heap representation and iterative sift-down use constant auxiliary array storage.

90. What integer comparator avoids subtraction overflow for qsort?
Answer and explanation for question 90

A. (a > b) - (a < b) — Relational results are 0 or 1, so their difference safely gives a negative, zero or positive result.

Bits, concurrency and portability

91. Which operation tests whether any bit in mask is set in value?
Answer and explanation for question 91

D. (value & mask) != 0 — Bitwise AND retains shared set bits; comparing with zero then tests whether any remain.

92. Which operation clears the bits selected by an unsigned mask?
Answer and explanation for question 92

B. value &= ~mask — Complementing the mask creates zeros at selected positions; AND clears those positions.

93. Which operation toggles bits selected by a mask?
Answer and explanation for question 93

D. value ^= mask — XOR flips a bit where the mask has 1 and leaves it unchanged where the mask has 0.

94. Which shift count is invalid in C?
Answer and explanation for question 94

B. A negative count or one at least the promoted left operand width — Shift counts are constrained by the promoted operand width. Other signed-operand restrictions can apply too.

95. Does volatile provide a portable mutex for threads?
Answer and explanation for question 95

B. No — volatile is not mutual exclusion, atomicity or a general synchronization guarantee. Use appropriate atomics or locks.

96. Why can value |= mask be unsafe for a hardware register?
Answer and explanation for question 96

A. Register side effects and concurrent changes may make read-modify-write invalid — Registers may have write-one-to-clear or other special semantics. Follow the actual device manual.

97. What must a portable byte-oriented protocol define?
Answer and explanation for question 97

A. Field encoding and byte order, with explicit width assumptions — Protocols should not inherit padding and machine representation accidentally from an in-memory struct.

98. Can a hosted online C compiler validate real interrupt latency on a board?
Answer and explanation for question 98

C. No, that requires the actual target or a suitable hardware test setup — Host language tests can check pure logic, not establish real peripheral timing or electrical behavior.

99. What does a watchdog primarily help detect?
Answer and explanation for question 99

C. Failure to make expected progress within a configured time — It requires a meaningful servicing policy; blindly feeding it can hide a stuck application.

100. What is required when interpreting wrapping unsigned timer subtraction?
Answer and explanation for question 100

D. A bound on elapsed time and a sampling policy that avoids ambiguous wraps — Modular differences are meaningful only under the stated wrap and observation constraints; deadline comparisons may need stricter limits.

Back to quiz topics and score