Top 40 C Programming Interview & College Viva Questions with Answers (2026 Edition)
Ace your BCA, B.Tech 1st/2nd semester practical lab viva and IT placement interviews with the top 40 C programming questions, pointer concepts, memory allocation, and code snippets.
Whether you are preparing for your 1st/2nd semester BCA, B.Sc Computer Science, or B.Tech practical lab viva, C programming is the most foundational subject examiners test. External examiners evaluate whether you truly grasp memory addresses, pointers, and compilation cycles or simply memorized syntax.
Here is a curated compilation of the top questions most frequently asked by college viva examiners and fresher campus placement interviewers, compiled by Er. Sumit Kumar at MSK Institute.
1. What is the difference between malloc(), calloc(), realloc(), and free()?
This is universally the #1 favorite question in dynamic memory management:
| Function | Signature | Initialization | Use Case |
|---|---|---|---|
malloc(size) | void* malloc(size_t size) | Garbage values | Allocates single contiguous block of specified bytes. |
calloc(n, size) | void* calloc(size_t n, size_t size) | Zero (0) | Allocates memory for array of elements initialized to 0. |
realloc(ptr, size) | void* realloc(void* ptr, size_t size) | Preserves existing data | Dynamically resizes previously allocated memory. |
free(ptr) | void free(void* ptr) | Releases memory | Deallocates heap memory back to the OS to avoid memory leaks. |
NULL check is mandatory before accessing dynamically allocated pointers!2. What is a Dangling Pointer, Wild Pointer, and Null Pointer?
Examiners love asking you to contrast these three pointer states:
- 1Wild Pointer: A pointer variable that has been declared but not initialized. It points to an arbitrary, unpredictable memory location.
- 1Dangling Pointer: A pointer that points to a memory location that has already been deallocated or deleted.
- 1NULL Pointer: A pointer explicitly assigned to
NULL(value0), signifying that it points to no valid memory address.
3. What is the fundamental difference between Structure and Union?
Both define user-defined heterogeneous data types, but their memory footprints are drastically different:
- Structure (
struct): Every member gets its own independent memory space. The total size is at least the sum of all members' sizes (plus struct padding). - Union (
union): All members share the same single memory location. The total size is equal to the size of its largest data member. Only one member can hold a value at any given moment.
4. What is the difference between Call by Value and Call by Reference?
- Call by Value: A copy of the actual argument value is passed to the function parameter. Changes made inside the function do not affect the original caller variable.
- Call by Reference (Using Pointers in C): The memory address of the actual argument is passed using
&. The function dereferences the pointer (*) to modify the original variable directly in memory.
5. What are the four Storage Classes in C?
Storage classes define the scope, lifetime, default initial value, and memory location of variables:
- 1
auto(Automatic): Default for local variables. Stored on Stack. Scope: Local to block. Lifetime: Until block exits. Initial value: Garbage. - 2
static: Retains its value between multiple function invocations. Stored in Data Segment. Scope: Local to function/file. Lifetime: Throughout program execution. Default:0. - 3
extern(External): Global variable defined in another file or outer scope. - 4
register: Requests the compiler to store the variable inside a CPU register instead of RAM for ultra-fast access (frequently used in loop counters).
6. What is a Segmentation Fault (Core Dumped) and what triggers it?
A Segmentation Fault (SegFault) occurs when a program attempts to access a memory segment that it is not authorized to read or write by the operating system.
Common triggers:
- Dereferencing a
NULLor wild pointer (*ptr = 10;whenptr = NULL). - Writing past array boundaries (Buffer Overflow).
- Stack Overflow caused by infinite recursion.
- Writing to read-only string literals (
char *str = "Hello"; str[0] = 'M';).
7. How does a Preprocessor Macro (#define) differ from typedef?
#define: Processed by the C Preprocessor before compilation via simple textual substitution. It does not perform type checking.typedef: Processed by the C Compiler itself. It creates a formal type alias and obeys scope rules with full compiler type checking.
8. How to reverse a string in-place without strrev()?
Examiners often ban standard library string functions to test your fundamental pointer manipulation:
9. How to swap two numbers without a third variable using bitwise XOR?
10. Summary & Top 5 Golden Rules for College Lab Viva
- 1Be Confident with Pointer Symbols: Always explain that
&means "Address of" and*when used with a pointer variable means "Value at address (dereference)". - 2Never Write Code on Paper Without Semicolons: Examiners instantly deduct marks for missing semicolons and unclosed braces.
- 3Explain Memory Allocation Verbally: Don't just recite code; explain that local variables reside on the Stack, dynamic allocations on the Heap, and global constants in the Data Segment.
- 4Practice Running Code Live: Use our free browser compiler at MSK Code Playground to test pointer math and string manipulations right now.
- 5Join Our Hands-On Coding Lab: At MSK Institute in Shikohabad and our interactive online live batches, students write and debug over 150+ algorithms with personal mentor feedback.
Master These Skills in Our Offline Labs
Data Structures & Algorithms (DSA) Mastery Course: Zero to FAANG
Master Data Structures and Algorithms from ground zero to FAANG-level problem-solving. Covers Big-O analysis, Two Pointers, Sliding Window, Linked Lists, Stacks, Queues, Hash Tables, Trees, Graphs, Dynamic Programming, and System Optimization with multi-language implementations (JavaScript, Python, C++) and rich visual diagrams.
Full-Stack Web Development Grand Mastery (Multi-Stack Architect) - 18 Months
The ultimate 1.5-year software engineering flagship program. Master Dual-Stack Web Development covering Frontend (React.js, Next.js 15, Tailwind CSS), Node.js & Express, Python & Django REST Framework, Dual Databases (SQL & MongoDB NoSQL), System Design, and Cloud DevOps.