C Interview Questions
How C interviews work
C interviews usually mix three things: concept questions ("what is the difference between..."), pointer and memory puzzles, and small coding problems to write on paper or a screen. This lesson collects the questions that come up again and again, with short, clear answers you can actually remember.
For deeper coverage of any topic, follow the linked lessons — this page is a revision hub.
Concept questions and answers
| Question | Short answer |
|---|---|
| Array vs pointer? | Array is a fixed block; pointer holds a reassignable address. See arrays and pointers. |
| Structure vs union? | Struct gives each member its own memory; union shares one. See structure vs union. |
| What is a storage class? | It sets a variable's lifetime and visibility (auto, static, extern, register). See storage classes. |
| Call by value vs reference? | Value copies the data; reference passes an address so changes stick. See call by value/reference. |
Pointer and memory questions
- What is a NULL pointer? A pointer that points to nothing, written as
NULL. Always check before dereferencing. - What is a dangling pointer? A pointer to memory that was already freed. Set pointers to
NULLafterfree. - malloc vs calloc?
mallocleaves memory uninitialised;calloczeroes it. See dynamic memory. - What is a memory leak? Allocated memory never freed, so usage grows until the program ends.
Be ready to draw boxes and arrows. Explaining a pointer with a quick memory diagram impresses more than reciting a definition.
Common coding problems
These small programs come up constantly. Make sure you can write each from memory:
- Reverse a string or a number.
- Check if a number is prime or a string is a palindrome.
- Swap two numbers without a third variable.
- Find the largest element in an array.
- Build and traverse a linked list; reverse it.
- Factorial and Fibonacci, both loop and recursion versions.
int isPalindrome(char s[]) {
int i = 0, j = 0;
while (s[j] != '\0') j++; // find length
j--;
while (i < j)
if (s[i++] != s[j--]) return 0; // mismatch
return 1; // all matched
}Preparation tips
- Practise writing code by hand — many interviews are on paper or a whiteboard.
- Explain your thinking out loud as you code; interviewers score reasoning.
- Know the why, not just the definition — be ready for "why does that happen?"
- Revise pointers, memory and strings most; they appear in almost every C interview.
Pick five questions above and answer each out loud in your own words, then write the coding ones from a blank editor without looking. That mirrors real interview pressure.
Summary
- C interviews mix concept questions, pointer/memory puzzles and coding problems.
- Master array vs pointer, struct vs union, storage classes and call by value/reference.
- Be fluent with NULL and dangling pointers, malloc vs calloc, and memory leaks.
- Practise classic programs (reverse, palindrome, linked list) by hand.
- Explain your reasoning aloud and focus revision on pointers, memory and strings.
Frequently Asked Questions
What is the difference between an array and a pointer in C?
What is the difference between malloc and calloc?
malloc takes one size argument and leaves the memory uninitialised, while calloc takes a count and a size, allocates that many elements, and sets every byte to zero. Use calloc when you need the memory cleared to start.What is a dangling pointer?
NULL right after freeing what it pointed to.What is the difference between structure and union in C?
What is the use of the static keyword in C?
static makes a local variable keep its value between calls instead of being recreated each time. At file level, static limits a variable or function to that file, hiding it from other files. Both uses are common interview topics.