C Programming with DSA Interview Questions & Answers
All 200 unique questions in one place — 62 easy, 94 medium, 44 hard — grouped by topic.
Practise by topic
Practise the way your interview works
What are the basic data types in C and their typical sizes?
Show answer
What is the difference between a declaration and a definition in C?
Show answer
What does the static keyword do in different contexts?
Show answer
What is the difference between ++i and i++?
Show answer
A program prints garbage values for a local variable. What is the likely cause?
Show answer
Write a C program to swap two numbers without using a third variable.
Show answer
Write a C function to check whether a number is an Armstrong number.
Show answer
Write a header guard and explain why it is needed.
Show answer
Why do you want to work in C and systems programming?
Show answer
What is the difference between break and continue in C?
Show answer
Explain storage classes in C.
Show answer
What is the difference between a macro and an inline function?
Show answer
What is the volatile qualifier used for in C?
Show answer
What is the difference between const int *p, int *const p and const int *const p?
Show answer
Explain the memory layout of a C program.
Show answer
A loop that sums large numbers gives a negative result. What is happening?
Show answer
Two source files both define a global variable named count and the build fails. How do you fix it?
Show answer
Write C code to count the number of set bits in an integer.
Show answer
How do you set, clear and toggle a particular bit in C?
Show answer
Which gcc flags would you use to build and debug a C program safely?
Show answer
Tell me about a time you debugged a hard crash in C code.
Show answer
What is undefined behaviour in C? Give examples.
Show answer
What is integer promotion and why does it matter?
Show answer
Code works with -O0 but fails with -O2. How do you approach this?
Show answer
What is a pointer in C?
Show answer
What are null, dangling, wild and void pointers?
Show answer
What is the difference between malloc, calloc, realloc and free?
Show answer
What is the difference between stack and heap allocation?
Show answer
Write a function that dynamically allocates an array of n integers and fills it with squares.
Show answer
Write a function that swaps two integers using pointers.
Show answer
What does sizeof return for a pointer and for an array?
Show answer
Explain pointer arithmetic in C.
Show answer
What is the difference between an array and a pointer?
Show answer
What is a memory leak and how do you detect it?
Show answer
What is a function pointer and where is it used?
Show answer
What is a double pointer and when do you need it?
Show answer
A program crashes with a segmentation fault. How do you find the cause?
Show answer
A function returns the address of a local array and the caller gets wrong data. Why?
Show answer
After calling realloc, the program sometimes crashes. What could be wrong?
Show answer
Allocate and free a dynamic 2D array of rows by cols in C.
Show answer
Use qsort with a function pointer to sort an array of integers in descending order.
Show answer
Tell me about a time you fixed a memory leak.
Show answer
How do you write C code that other developers can maintain?
Show answer
What is the strict aliasing rule?
Show answer
What is memory alignment and why does it matter?
Show answer
Memory use of a long running C service grows every hour. How do you investigate?
Show answer
Valgrind reports invalid read of size 4 after free. How do you fix it?
Show answer
Implement your own version of memcpy.
Show answer
Write a simple fixed-size memory pool allocator in C.
Show answer
How are strings represented in C?
Show answer
What is the difference between char s[] = "hello" and char *s = "hello"?
Show answer
Why is gets() dangerous and what should you use instead?
Show answer
What is the two-pointer technique and when is it used?
Show answer
An interview asks you to find the missing number from 1 to n in an array of n-1 numbers. What approaches work?
Show answer
Reverse a string in place in C.
Show answer
Merge two sorted arrays into a third sorted array.
Show answer
Implement your own strcmp function.
Show answer
Write a C function to count words in a sentence.
Show answer
How did you improve your problem solving skills?
Show answer
What does it mean that arrays decay to pointers when passed to functions?
Show answer
What is the difference between strcpy, strncpy and snprintf for copying strings?
Show answer
How is a 2D array stored in memory in C?
Show answer
What is the sliding window technique?
Show answer
What is a prefix sum array and why is it useful?
Show answer
Explain Kadane's algorithm.
Show answer
A strlen call crashes on a buffer received from a network packet. What is wrong?
Show answer
You need to find whether any two numbers in an unsorted array sum to a target. Compare approaches.
Show answer
Write Kadane's algorithm in C.
Show answer
Rotate an array to the right by k positions in O(n) time and O(1) space.
Show answer
Find the length of the longest substring without repeating characters in C.
Show answer
Describe how you approach a coding problem you have never seen before.
Show answer
What is a buffer overflow and how can it be prevented in C?
Show answer
A matrix multiplication in C is very slow for 2000 by 2000 matrices. How would you speed it up?
Show answer
Find the majority element that appears more than n/2 times in O(n) time and O(1) space.
Show answer
What is a structure in C and why is it used?
Show answer
What is the difference between a structure and a union?
Show answer
What is typedef and how is it used with structures?
Show answer
What is an enum in C and what are its advantages?
Show answer
A file opened with fopen is NULL in production but fine on your machine. How do you debug?
Show answer
Define a struct for a student and print all students with marks above 75.
Show answer
How do you pass a structure to a function efficiently?
Show answer
What is structure padding and how can you reduce it?
Show answer
What are bit fields in C?
Show answer
What is the difference between text and binary file modes?
Show answer
What is the difference between fseek, ftell and rewind?
Show answer
A program reads a file with while (!feof(fp)) and processes the last line twice. Why?
Show answer
You need to update one record in the middle of a large binary file without rewriting it all. How?
Show answer
Write a C program that counts lines, words and characters in a file.
Show answer
Copy a file in C using fread and fwrite.
Show answer
Write code to check whether the machine is little endian or big endian.
Show answer
Use a tagged union to store either an int, a float or a string value.
Show answer
Tell me about a project where you worked with files or binary data in C.
Show answer
How do you handle a situation where requirements change late in a project?
Show answer
A program that writes logs with fprintf loses the last lines when it crashes. Why, and how do you fix it?
Show answer
Why is it risky to write structs directly to a file with fwrite?
Show answer
What is a flexible array member?
Show answer
Your embedded device must store 10,000 sensor records in limited RAM. How would you design the struct?
Show answer
Two programs on different machines exchange a binary struct and values come out wrong. What is happening?
Show answer
Write a static assertion that checks a struct size at compile time.
Show answer
What is a linked list and how is it different from an array?
Show answer
What are the types of linked lists?
Show answer
What is the time complexity of common linked list operations?
Show answer
How do you find the middle of a linked list in one pass?
Show answer
A function to insert at the head does not change the list in main. Why?
Show answer
Describe a time you failed in an interview or test and what you learned.
Show answer
What is a circular linked list and where is it used?
Show answer
How does Floyd's cycle detection algorithm work?
Show answer
Why is a dummy or sentinel node useful in linked list code?
Show answer
How would you detect if two linked lists intersect and find the intersection node?
Show answer
Your linked list program crashes when deleting the last node. What do you check?
Show answer
Freeing a linked list causes a crash. What is the common mistake?
Show answer
Reverse a singly linked list iteratively in C.
Show answer
Insert a node at the end of a singly linked list using a double pointer.
Show answer
Merge two sorted linked lists into one sorted list.
Show answer
Tell me about a time you explained a complex data structure to your team.
Show answer
How do you prioritise between writing fast code and readable code?
Show answer
How do you check whether a linked list is a palindrome in O(1) extra space?
Show answer
A doubly linked list delete function leaves the list broken when deleting the head. What is missing?
Show answer
Why do linked lists perform poorly compared to arrays on modern CPUs?
Show answer
What is an XOR linked list?
Show answer
You must design an LRU cache in C with O(1) get and put. How would you build it?
Show answer
A linked list used in a multithreaded C server sometimes corrupts. How would you fix it?
Show answer
Detect a cycle in a linked list and return the node where it starts.
Show answer
Remove the nth node from the end of a linked list in one pass.
Show answer
What is a stack and where is it used?
Show answer
What is a queue and what are its variants?
Show answer
Implement a stack using an array in C.
Show answer
Check whether brackets in an expression are balanced using a stack.
Show answer
How do you handle working with a teammate who writes buggy code?
Show answer
What is a deque and how can it be implemented in C?
Show answer
Why is a circular queue better than a simple array queue?
Show answer
What is a hash table and how are collisions handled?
Show answer
What is a monotonic stack?
Show answer
What is a heap and how does it implement a priority queue?
Show answer
How do you convert an infix expression to postfix?
Show answer
Your stack implementation crashes with deep recursion converted to an explicit stack. What would you check?
Show answer
You need to look up 10 lakh user ids quickly in a C program. What structure do you choose?
Show answer
A hash table becomes slow as more data is inserted. What is wrong?
Show answer
Implement a circular queue with enqueue and dequeue in C.
Show answer
Find the next greater element for every array element using a monotonic stack.
Show answer
Evaluate a postfix expression of single digit numbers using a stack.
Show answer
Tell me about a time you chose the right data structure under pressure.
Show answer
You need to implement a queue using two stacks. How does it work and what is its cost?
Show answer
What makes a good hash function?
Show answer
What is a ring buffer and why is it common in embedded systems?
Show answer
A UART receive buffer in firmware sometimes loses or duplicates bytes. How would you fix it?
Show answer
You need the maximum of every sliding window of size k in an array. How would you solve it efficiently?
Show answer
Implement a simple hash table with separate chaining for string keys.
Show answer
What is the difference between open addressing and separate chaining in terms of performance?
Show answer
What is a binary search tree and what are its operation costs?
Show answer
Explain the tree traversal orders.
Show answer
What is the difference between a complete, full and perfect binary tree?
Show answer
Insert a value into a binary search tree recursively in C.
Show answer
Find the height of a binary tree in C.
Show answer
How do you explain the time complexity of your solution to an interviewer?
Show answer
Why are self-balancing trees like AVL and red-black trees needed?
Show answer
How are graphs represented in C?
Show answer
Compare BFS and DFS.
Show answer
A recursive tree traversal crashes on a very large, skewed tree. How do you fix it?
Show answer
You need to find the shortest route between two cities on a map with distances. Which algorithm do you use and why?
Show answer
Count the number of islands in a grid of land and water cells. What approach do you take?
Show answer
How would you check whether a binary tree is a valid BST?
Show answer
Write BFS on a graph stored as an adjacency matrix.
Show answer
Find the lowest common ancestor of two nodes in a binary search tree.
Show answer
Tell me about a project where you applied graph algorithms.
Show answer
What is a trie and when is it better than a hash table?
Show answer
How does Dijkstra's algorithm work?
Show answer
What is topological sorting and where is it used?
Show answer
What is the union-find data structure?
Show answer
A build tool must compile modules in the correct dependency order and report circular dependencies. How would you design it?
Show answer
A social network feature must suggest friends of friends. How would you find them efficiently?
Show answer
Implement union-find with path compression and union by rank.
Show answer
Describe a time you had to make a trade-off between memory and speed.
Show answer
A Dijkstra implementation gives wrong distances on a graph with a few negative edges. Why?
Show answer
What is Big O notation?
Show answer
How does binary search work and what are common bugs?
Show answer
What is recursion and what are its risks?
Show answer
A recursive Fibonacci solution times out for n = 50. How do you fix it?
Show answer
A search on a sorted array of 10 lakh elements is done with a linear loop. How would you justify changing it?
Show answer
Write binary search in C that returns the index of the target or -1.
Show answer
How do you keep improving your DSA skills while working full time?
Show answer
Compare quicksort, merge sort and heap sort.
Show answer
What is dynamic programming?
Show answer
What is the difference between greedy algorithms and dynamic programming?
Show answer
Your program sorts 1 crore integers in the range 0 to 999 and qsort is too slow. What would you do?
Show answer
An interview asks for the minimum number of coins to make an amount. How do you approach it?
Show answer
You must schedule the maximum number of non-overlapping meetings in one room. What algorithm do you use?
Show answer
Implement quicksort in C using Lomuto partition.
Show answer
Implement merge sort in C.
Show answer
Tell me about a time you optimised an algorithm in a real project.
Show answer
How do you handle a coding interview problem when you are stuck?
Show answer
What is backtracking? Give an example.
Show answer
What is the master theorem used for?
Show answer
What is amortised analysis? Give an example.
Show answer
Quicksort in your code becomes very slow on already sorted input. Why and how do you fix it?
Show answer
A DP solution for a large grid uses too much memory. How can you reduce it?
Show answer
How would you find the kth smallest element in an unsorted array efficiently?
Show answer
Solve the 0/1 knapsack problem in C with a 1D DP array.
Show answer
Find the length of the longest common subsequence of two strings.
Show answer
Frequently asked questions
What jobs can I get after learning C programming with DSA?
C with data structures and algorithms prepares you for roles like C developer, embedded software engineer, firmware engineer, systems programmer and general software engineer. Semiconductor, automotive, telecom and networking companies hire C developers directly, while IT services and product companies test DSA in coding rounds for almost every software role. Strong DSA skills help you clear placements no matter which language you use later.
Who should join a C programming with DSA course?
The course suits BTech, BCA, MCA, BSc and diploma students, especially electronics and computer science students, as well as freshers preparing for placements and professionals moving into embedded or systems roles. No prior programming knowledge is needed because it starts from the basics. A logical mindset and willingness to practise coding problems daily matter more than your background.
How long does it take to learn C and DSA for interviews?
With two to three hours of daily practice, most learners become comfortable with C fundamentals and pointers in about six weeks and cover core data structures and algorithms in another eight weeks, which matches this 14 week plan. To be fully interview ready, keep solving problems regularly and aim for 200 to 300 well understood problems across all major topics.
Is C still worth learning in 2026?
Yes. C remains the main language for operating systems, embedded devices, automotive electronics, networking equipment and high performance libraries, and it consistently ranks among the most used languages. Learning C also teaches how memory, pointers and the machine really work, which makes you a better programmer in C++, Java, Python or Rust. Embedded and semiconductor hiring in India keeps demand steady.
Is C a good language for DSA and coding rounds?
C is excellent for understanding how data structures work, because you build linked lists, stacks, hash tables and trees yourself with pointers. Most coding platforms accept C, so you can use it in tests. The trade-off is that C has no built-in containers, so solutions take more code than in C++ or Java. Many learners study DSA in C and later add C++ STL for speed.
Which certification helps for C programming jobs?
The C Programming Language Certified Associate (CLA) and Certified Professional (CLP) exams from the C++ Institute are recognised credentials for C knowledge. For embedded roles, practical projects on boards like Arduino, STM32 or ESP32 carry strong weight. Recruiters mainly look at your coding test performance, GitHub projects and how well you explain pointers, memory and algorithms in interviews.