Home Interview C Programming Interview Questions: Master the Core Concepts
Intermediate 3 min · July 13, 2026

C Programming Interview Questions: Master the Core Concepts

Prepare for C programming interviews with top questions, solutions, complexity analysis, and expert tips.

N
Naren Founder & Principal Engineer

20+ years shipping production code across the stack, with years spent interviewing engineers. Written from production experience, not tutorials.

Follow
Production
production tested
July 13, 2026
last updated
2,165
articles · all by Naren
Before you start⏱ 15-20 min read
  • Basic knowledge of C syntax and control structures.
  • Familiarity with pointers and dynamic memory allocation.
  • Understanding of data structures like arrays and linked lists.
 ● Production Incident 🔎 Debug Guide ⚙ Triage Commands
Quick Answer
  • Focus on pointers, memory management, and data structures.
  • Understand undefined behavior and common pitfalls.
  • Practice writing clean, efficient C code.
  • Be ready to explain time and space complexity.
  • Use debugging techniques to identify issues quickly.
✦ Definition~90s read
What is C Programming Interview Questions?

C programming interview questions assess your understanding of low-level concepts like pointers, memory management, and data structures.

Think of C as a manual car: you have full control over the engine (memory) and gears (pointers).
Plain-English First

Think of C as a manual car: you have full control over the engine (memory) and gears (pointers). Unlike automatic cars (like Python), you must shift gears yourself. Interviewers want to see if you can drive this manual car without stalling.

⚙ Browser compatibility
Latest versions — ✓ supported
ChromeFirefoxSafariEdge

C is the backbone of modern computing—powering operating systems, embedded devices, and high-performance applications. In interviews, C questions test your understanding of low-level concepts like memory management, pointers, and data structures. This article covers the most frequently asked C interview questions, from basic syntax to advanced topics like dynamic memory allocation and bit manipulation. Each question includes a solution with time and space complexity analysis, plus tips on how to present your answer in an interview. Whether you're preparing for a systems programming role or a general software engineering position, mastering these concepts will set you apart. Let's dive into the essential C interview questions that every developer should know.

1. Pointers and Memory Management

Pointers are a fundamental concept in C. Interviewers often ask about pointer arithmetic, null pointers, and dynamic memory allocation. A common question is: 'Write a function to reverse a string in place using pointers.' The solution involves using two pointers—one at the start and one at the end—and swapping characters until they meet. This demonstrates understanding of pointer arithmetic and memory manipulation. Another frequent topic is the difference between malloc, calloc, and realloc. malloc allocates uninitialized memory, calloc allocates zero-initialized memory, and realloc resizes previously allocated memory. Always check the return value of malloc for NULL to handle allocation failure.

reverse_string.cC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
#include <string.h>

void reverse_string(char *str) {
    char *start = str;
    char *end = str + strlen(str) - 1;
    while (start < end) {
        char temp = *start;
        *start = *end;
        *end = temp;
        start++;
        end--;
    }
}

int main() {
    char s[] = "hello";
    reverse_string(s);
    printf("%s\n", s);
    return 0;
}
Output
olleh
💡Interview Tip
📊 Production Insight
In production, use static analysis tools to detect null pointer dereferences before they cause crashes.
🎯 Key Takeaway
Master pointer arithmetic and always handle malloc failures.

2. Strings and Character Arrays

C strings are null-terminated character arrays. Common interview questions include finding the length of a string without using strlen, checking for palindromes, and implementing strcpy or strcat. A classic problem is: 'Implement atoi to convert a string to an integer.' This requires handling leading whitespace, optional sign, and overflow. Another is 'Find the first non-repeating character in a string.' Use a hash table (or array of size 256) to count frequencies, then traverse again to find the first character with count 1. Be careful with null terminators and buffer overflows—always ensure destination buffers are large enough.

atoi.cC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>
#include <limits.h>

int my_atoi(const char *str) {
    int sign = 1, result = 0, i = 0;
    while (str[i] == ' ') i++;
    if (str[i] == '-' || str[i] == '+') {
        sign = (str[i++] == '-') ? -1 : 1;
    }
    while (str[i] >= '0' && str[i] <= '9') {
        if (result > INT_MAX / 10 || (result == INT_MAX / 10 && str[i] - '0' > INT_MAX % 10)) {
            return (sign == 1) ? INT_MAX : INT_MIN;
        }
        result = result * 10 + (str[i++] - '0');
    }
    return result * sign;
}

int main() {
    printf("%d\n", my_atoi("   -123"));
    return 0;
}
Output
-123
⚠ Common Pitfall
📊 Production Insight
In production, use strncpy and snprintf instead of strcpy and sprintf to prevent buffer overflows.
🎯 Key Takeaway
Always consider edge cases like empty strings, signs, and overflow.

3. Data Structures: Linked Lists

Linked lists are a staple in C interviews. You may be asked to reverse a linked list, detect a cycle, or find the middle element. Reversing a linked list iteratively uses three pointers: prev, current, and next. For cycle detection, Floyd's cycle-finding algorithm (tortoise and hare) is efficient. Another common question is merging two sorted linked lists. The solution uses a dummy node to simplify the merging process. Always handle edge cases like empty lists and single-node lists.

reverse_linked_list.cC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node* next;
};

struct Node* reverse(struct Node* head) {
    struct Node *prev = NULL, *current = head, *next = NULL;
    while (current != NULL) {
        next = current->next;
        current->next = prev;
        prev = current;
        current = next;
    }
    return prev;
}

void printList(struct Node* head) {
    while (head) {
        printf("%d ", head->data);
        head = head->next;
    }
    printf("\n");
}

int main() {
    struct Node* head = malloc(sizeof(struct Node));
    head->data = 1; head->next = malloc(sizeof(struct Node));
    head->next->data = 2; head->next->next = malloc(sizeof(struct Node));
    head->next->next->data = 3; head->next->next->next = NULL;
    head = reverse(head);
    printList(head);
    return 0;
}
Output
3 2 1
🔥Complexity
📊 Production Insight
In production, avoid recursion for large lists due to stack limits; use iterative approaches.
🎯 Key Takeaway
Iterative reversal is efficient and avoids recursion stack overflow.

4. Bit Manipulation

Bit manipulation questions test your understanding of binary operations. Common tasks: check if a number is power of two, count set bits, or find the only non-repeating element in an array where every other element repeats twice. For power of two, use n > 0 && (n & (n-1)) == 0. For counting set bits, Brian Kernighan's algorithm repeatedly clears the lowest set bit. For the non-repeating element, XOR all numbers; the result is the unique element. These questions are popular because they demonstrate low-level thinking.

count_set_bits.cC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>

int countSetBits(int n) {
    int count = 0;
    while (n) {
        n &= (n - 1);
        count++;
    }
    return count;
}

int main() {
    printf("%d\n", countSetBits(7));
    return 0;
}
Output
3
💡Interview Tip
📊 Production Insight
Bit manipulation is used in performance-critical code like network protocols and graphics.
🎯 Key Takeaway
Bit manipulation solutions are often O(1) or O(number of set bits).

5. Dynamic Memory Allocation and Structures

Questions about dynamic memory allocation often involve creating and manipulating structures. For example, implement a function to create a 2D array dynamically. This requires allocating an array of pointers, then each row. Another common question is implementing a stack using dynamic arrays or linked lists. Always free memory to avoid leaks. Interviewers may ask about the difference between struct and union, or padding and alignment. Use #pragma pack or __attribute__((packed)) to control padding.

dynamic_2d_array.cC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#include <stdlib.h>

int** create2DArray(int rows, int cols) {
    int **arr = (int**)malloc(rows * sizeof(int*));
    for (int i = 0; i < rows; i++) {
        arr[i] = (int*)malloc(cols * sizeof(int));
    }
    return arr;
}

void free2DArray(int **arr, int rows) {
    for (int i = 0; i < rows; i++) free(arr[i]);
    free(arr);
}

int main() {
    int **arr = create2DArray(3, 4);
    arr[0][0] = 5;
    printf("%d\n", arr[0][0]);
    free2DArray(arr, 3);
    return 0;
}
Output
5
⚠ Memory Leak Alert
📊 Production Insight
In production, use memory pools or custom allocators to reduce fragmentation.
🎯 Key Takeaway
Always pair malloc with free, and handle allocation failures.

6. Recursion and Function Pointers

Recursion questions often involve tree traversals, factorial, or Fibonacci. However, C interviewers may ask about function pointers—pointers that store the address of a function. For example, implement a sorting function that takes a comparison function pointer. This is the basis of qsort. Another question: write a recursive function to compute the nth Fibonacci number, but discuss its exponential time complexity and suggest memoization. Understanding recursion depth and stack overflow is crucial.

function_pointer_example.cC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>

int add(int a, int b) { return a + b; }
int multiply(int a, int b) { return a * b; }

int operate(int (*op)(int, int), int x, int y) {
    return op(x, y);
}

int main() {
    printf("%d\n", operate(add, 5, 3));
    printf("%d\n", operate(multiply, 5, 3));
    return 0;
}
Output
8
15
🔥Complexity
📊 Production Insight
Function pointers are used in event-driven systems and plugin architectures.
🎯 Key Takeaway
Function pointers enable polymorphism in C and are used in callback mechanisms.
● Production incidentPOST-MORTEMseverity: high

The Dangling Pointer Disaster

Symptom
Random crashes and data corruption in a web server.
Assumption
The developer assumed the pointer was still valid after freeing memory.
Root cause
A dangling pointer: memory was freed but the pointer was not set to NULL, leading to use-after-free.
Fix
Set pointer to NULL after free and add checks before dereferencing.
Key lesson
  • Always set pointers to NULL after freeing.
  • Use tools like Valgrind to detect memory errors.
  • Implement defensive programming with null checks.
  • Consider using smart pointers in C++ or wrappers in C.
  • Review code for double-free and use-after-free patterns.
Production debug guideSymptom to Action4 entries
Symptom · 01
Segmentation fault
Fix
Check for null pointer dereference or buffer overflow. Use gdb to get backtrace.
Symptom · 02
Memory leak
Fix
Use Valgrind or AddressSanitizer to identify unfreed memory.
Symptom · 03
Unexpected output
Fix
Check for uninitialized variables and integer overflow.
Symptom · 04
Stack overflow
Fix
Look for infinite recursion or large local arrays.
★ Quick Debug Cheat SheetCommon C errors and immediate actions.
Segfault
Immediate action
Run with gdb, get backtrace
Commands
gdb ./program core
bt
Fix now
Fix null pointer or array bounds
Memory leak+
Immediate action
Run Valgrind
Commands
valgrind --leak-check=full ./program
Fix now
Free all allocated memory
Buffer overflow+
Immediate action
Use AddressSanitizer
Commands
gcc -fsanitize=address -g program.c
./a.out
Fix now
Use safer functions like snprintf
Featuremalloccalloc
InitializationUninitializedZero-initialized
Arguments1 (size)2 (count, size)
Returnvoid*void*
Use caseWhen initialization not neededWhen zero-initialized memory required
⚙ Quick Reference
6 commands from this guide
FileCommand / CodePurpose
reverse_string.cvoid reverse_string(char *str) {1. Pointers and Memory Management
atoi.cint my_atoi(const char *str) {2. Strings and Character Arrays
reverse_linked_list.cstruct Node {3. Data Structures
count_set_bits.cint countSetBits(int n) {4. Bit Manipulation
dynamic_2d_array.cint** create2DArray(int rows, int cols) {5. Dynamic Memory Allocation and Structures
function_pointer_example.cint add(int a, int b) { return a + b; }6. Recursion and Function Pointers

Key takeaways

1
Master pointers and memory management as they are central to C.
2
Practice common data structures like linked lists and strings.
3
Understand bit manipulation for low-level optimization.
4
Always handle edge cases and undefined behavior.

Common mistakes to avoid

3 patterns
×

Forgetting to free dynamically allocated memory.

×

Off-by-one errors in array indexing.

×

Not checking return value of malloc.

INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01SENIOR
Write a function to reverse a linked list iteratively.
Q02SENIOR
Implement atoi (string to integer) in C.
Q03JUNIOR
Find the first non-repeating character in a string.
Q01 of 03SENIOR

Write a function to reverse a linked list iteratively.

ANSWER
Use three pointers: prev, current, next. Initialize prev=NULL, current=head. While current, store next, set current->next=prev, move prev and current. Return prev as new head. Time O(n), Space O(1).
FAQ · 3 QUESTIONS

Frequently Asked Questions

01
What is the difference between malloc and calloc?
02
How do you avoid buffer overflow in C?
03
What is a null pointer and why is it dangerous?
N
Naren Founder & Principal Engineer

20+ years shipping production code across the stack, with years spent interviewing engineers. Written from production experience, not tutorials.

Follow
Verified
production tested
July 13, 2026
last updated
2,165
articles · all by Naren
🔥

That's Coding Patterns. Mark it forged?

3 min read · try the examples if you haven't

Previous
Rust Interview Questions
24 / 26 · Coding Patterns
Next
C++ Interview Questions