Learning Resources
Top 50 Interview MCQ
Top 50 C multiple-choice questions covering all concepts of the language. Choose an option and press Show Answer to see instantly whether you were right, along with the reason.
C Interview MCQ Practice
Fifty multiple-choice questions covering every concept of C — basics, data types, operators, control flow, arrays, strings, functions, recursion, storage classes, pointers, dynamic memory, structures, file handling, the preprocessor, enum and typedef. Pick an option, then press Show Answer to find out whether you were right and why.
Which of the following is the correct entry point of every C program?
Correct answer: B. main()
Why: Execution always begins at main(), no matter where it appears in the file.
Who developed the C programming language?
Correct answer: C. Dennis Ritchie
Why: Dennis Ritchie developed C at Bell Laboratories in 1972.
How many keywords are there in standard C89?
Correct answer: A. 32
Why: C89 defines 32 keywords. C99 and C11 added a few more, mostly underscore-prefixed.
What is the output of printf("%d", sizeof(char)); on any conforming compiler?
Correct answer: A. 1
Why: sizeof(char) is defined by the standard to be exactly 1 on every implementation.
Which format specifier is used to print a double with scanf?
Correct answer: B. %lf
Why: scanf needs %lf for a double. printf accepts %f for both float and double due to promotion.
What does the volatile keyword tell the compiler?
Correct answer: B. The variable may change unexpectedly, do not optimise it
Why: volatile forces a fresh read from memory every time, because hardware or another thread may change it.
What is the value of 5 / 2 in C?
Correct answer: B. 2
Why: Both operands are int, so integer division discards the fractional part.
If int i = 5; what is the value of j after j = i++;?
Correct answer: A. 5
Why: Post-increment yields the old value, so j gets 5 and i becomes 6.
What does the expression 8 >> 2 evaluate to?
Correct answer: A. 2
Why: Right shifting by 2 divides by 2^2, so 8 becomes 2.
Which is the only ternary operator in C?
Correct answer: A. ? :
Why: The conditional operator condition ? expr1 : expr2 is the only operator taking three operands.
In the expression (a && b), when is b NOT evaluated?
Correct answer: B. When a is false
Why: Logical AND short-circuits: if a is false the result is already 0, so b is skipped.
Which loop is guaranteed to execute its body at least once?
Correct answer: C. do-while
Why: do-while is exit controlled — the condition is tested after the body runs.
What happens if break is omitted in a switch case?
Correct answer: C. Execution falls through to the next case
Why: Without break, control continues into the following cases — the classic fall-through bug.
Which data type is NOT allowed in a switch expression?
Correct answer: D. float
Why: The switch expression must be integral. Floating-point values are not permitted.
What does the continue statement do inside a loop?
Correct answer: B. Skips the rest of the current iteration
Why: continue jumps to the next iteration; break is what exits the loop.
What happens when you access an array beyond its bounds?
Correct answer: C. Undefined behaviour
Why: C performs no bounds checking, so the result is undefined — garbage, corruption, or a crash.
How is a 2D array stored in memory in C?
Correct answer: B. Row-major order
Why: All of row 0 is stored first, then row 1, and so on, in one contiguous block.
What is the expression a[i] equivalent to?
Correct answer: A. *(a + i)
Why: Subscripting is defined as *(a + i), which is why i[a] also compiles.
Inside a function with parameter int a[], what does sizeof(a) give?
Correct answer: B. The size of a pointer
Why: The array decays to a pointer at the call, so sizeof measures the pointer.
For char s[10] = "hello"; what are strlen(s) and sizeof(s)?
Correct answer: B. 5 and 10
Why: strlen counts characters before the terminator; sizeof reports the whole allocated array.
Which function is the safe replacement for gets()?
Correct answer: B. fgets
Why: fgets takes a size limit, so it cannot overflow the buffer. gets was removed in C11.
How do you correctly compare two strings s1 and s2?
Correct answer: B. strcmp(s1, s2) == 0
Why: == compares addresses. strcmp returns 0 when the contents match.
What is wrong with char *s = "hi"; s[0] = 'H';?
Correct answer: B. It modifies a string literal — undefined behaviour
Why: String literals usually live in read-only memory, so writing to them typically crashes.
C passes arguments to functions by which mechanism?
Correct answer: B. Call by value
Why: C is always call by value; passing an address simulates call by reference.
What is the purpose of a function prototype?
Correct answer: B. To tell the compiler the return type and parameter types in advance
Why: The prototype lets the compiler check argument counts and types at every call site.
What must every recursive function have to terminate?
Correct answer: B. A base case
Why: Without a reachable base case the recursion never stops and the stack overflows.
What does a static local variable retain between function calls?
Correct answer: B. Its value
Why: A static local is created once with a program-long lifetime, so its value persists across calls.
Which storage class makes a global variable private to its own source file?
Correct answer: C. static
Why: static at file scope gives internal linkage, hiding the name from other translation units.
Which operation is illegal on a register variable?
Correct answer: B. Taking its address with &
Why: A register variable may have no memory address, so & is not allowed on it.
What does a pointer variable store?
Correct answer: B. A memory address
Why: A pointer holds the address of another object; its type says how to interpret that address.
What is a dangling pointer?
Correct answer: B. A pointer to freed or out-of-scope memory
Why: The memory is gone but the pointer still holds its old address. Set it to NULL after free.
If int *p points to an int and p holds address 1000, what is p + 1 on a 4-byte-int machine?
Correct answer: B. 1004
Why: Pointer arithmetic is scaled by the size of the target type.
Which pointer type can hold the address of any data type?
Correct answer: C. void *
Why: void * is the generic pointer, but it must be cast before it can be dereferenced.
In const char *p, what is constant?
Correct answer: B. The character pointed to
Why: You cannot modify *p, but p itself can be pointed elsewhere. char * const p is the reverse.
Which function allocates memory and initialises it to zero?
Correct answer: B. calloc
Why: calloc takes a count and element size and zero-fills the block; malloc leaves it uninitialised.
What does malloc return when it fails?
Correct answer: B. NULL
Why: Always check the returned pointer against NULL before using it.
Where is dynamically allocated memory stored?
Correct answer: B. Heap
Why: malloc, calloc, and realloc allocate from the heap, which you must free explicitly.
What is sizeof a union with an int, a float, and a char (4-byte int and float)?
Correct answer: C. 4 bytes
Why: A union is as large as its largest member, since all members share the same memory.
Which operator accesses a structure member through a pointer?
Correct answer: B. ->
Why: p->x is shorthand for (*p).x. The dot is used on structure variables.
Can two structure variables be compared using ==?
Correct answer: B. No, C does not allow it
Why: C provides no structure comparison because padding bytes are indeterminate. Compare member by member.
Which fopen mode erases the contents of an existing file?
Correct answer: C. "w"
Why: "w" truncates the file to zero length as soon as fopen succeeds.
Why must the return of fgetc be stored in an int rather than a char?
Correct answer: B. To distinguish EOF from valid byte values
Why: EOF is typically −1 and must remain distinct from every valid byte, including 0xFF.
In main(int argc, char *argv[]), what does argv[0] contain?
Correct answer: B. The program name
Why: Real arguments begin at argv[1], and argv[argc] is always NULL.
What does #define SQ(x) x*x give for SQ(2+3)?
Correct answer: B. 11
Why: Text substitution produces 2+3*2+3 = 11. Write ((x)*(x)) to get 25.
What is the purpose of an include guard?
Correct answer: B. To prevent a header being included more than once
Why: The #ifndef / #define / #endif pattern stops redefinition errors from double inclusion.
What does the ## operator do in a macro?
Correct answer: B. Concatenates two tokens
Why: ## is token pasting; # is the stringizing operator.
Which predefined macro gives the current line number?
Correct answer: B. __LINE__
Why: __LINE__ expands to the line where it is written, which is why log macros use it.
In enum Color { RED, GREEN, BLUE };, what is the value of BLUE?
Correct answer: C. 2
Why: Numbering starts at 0 and increases by 1, so RED is 0, GREEN is 1, and BLUE is 2.
With #define P char * and the line P a, b; what is b?
Correct answer: B. A plain char
Why: It expands to char *a, b; so only a is a pointer. A typedef would make both pointers.
Which of these is the most common cause of a segmentation fault?
Correct answer: B. Dereferencing a NULL or dangling pointer
Why: A segmentation fault means touching memory the process does not own.