C Programming Interview Questions and Answers for Freshers

C is still the first language most engineering students learn, and interviewers love it because it shows whether you really understand memory. Service companies ask C basics in the technical round, and product companies use C output questions to test pointers. Below are the 40 most asked C interview questions for freshers with short answers you can speak in an interview.
Read the answer, then write a 3 to 5 line program for each topic. Pointers only become clear when you run code.
Quick summary
| Section | Questions | Focus |
|---|---|---|
| Basics | Q1 to Q8 | Features, data types, compilation |
| Operators and control | Q9 to Q13 | ++, sizeof, switch, loops |
| Functions and storage classes | Q14 to Q19 | Call by value, static, extern |
| Arrays and strings | Q20 to Q24 | Array decay, string functions |
| Pointers and memory | Q25 to Q33 | NULL, dangling, malloc, free |
| Structures and files | Q34 to Q37 | struct vs union, file modes |
| Output questions | Q38 to Q40 | Predict the result |
Basics
1. What is C?
A general-purpose, procedural programming language developed by Dennis Ritchie at Bell Labs in 1972. It is used for operating systems, embedded systems and compilers.
2. Why is C called a middle-level language?
It has high-level features like functions and loops, and also low-level access to memory through pointers and bit operators.
3. Main features of C?
Simple, fast, portable, structured (functions), rich library, direct memory access with pointers.
4. What are the basic data types?
int, char, float, double and void. Modifiers: short, long, signed, unsigned.
5. What are the stages of compiling a C program?
Preprocessing (expands #include and #define), compilation (to assembly), assembly (to object code), linking (adds library code to make the executable).
6. What is a header file?
A file with function declarations and macros, included with #include. Example: stdio.h for printf and scanf.
7. Difference between #include <file> and #include “file”?
Angle brackets search the system include folders. Quotes search the current folder first, then the system folders.
8. What is a macro?
A name replaced by its value before compilation, defined with #define. Example: #define PI 3.14. It has no type checking.
Operators and control
9. Difference between i++ and ++i?
i++ uses the value first and then increases it (post-increment). ++i increases first and then uses it (pre-increment).
10. What is sizeof?
A compile-time operator that gives the size in bytes of a type or variable. Example: sizeof(int) is usually 4.
11. Difference between = and ==?
= assigns a value. == compares two values and gives 1 (true) or 0 (false).
12. Difference between break and continue?
break exits the loop or switch. continue skips the rest of the current iteration and goes to the next one.
13. Difference between while and do-while?
while checks the condition first, so it may run zero times. do-while runs the body once before checking.
Functions and storage classes
14. What is a function prototype?
A declaration that tells the compiler the function’s name, return type and parameters before it is used.
15. Call by value vs call by reference?
Call by value passes a copy, so changes do not affect the original. Call by reference passes the address (a pointer), so changes affect the original.
16. What is recursion?
A function calling itself. It needs a base case to stop, or it causes a stack overflow. Example: factorial(n) = n x factorial(n – 1).
17. What are storage classes in C?
auto, register, static and extern. They decide the scope, lifetime and default value of a variable.
18. What does static do?
A static local variable keeps its value between function calls. A static global variable or function is visible only inside its file.
19. What is extern?
It declares a variable that is defined in another file, so many files can share one global variable.
Arrays and strings
20. What is an array?
A collection of elements of the same type stored in continuous memory, accessed by index starting from 0.
21. What is a string in C?
A character array ended by the null character ‘\0’.
22. Difference between strlen and sizeof for a string?
strlen counts characters before ‘\0’. sizeof gives the full array size including ‘\0’. For char s[10] = “hi”, strlen is 2 and sizeof is 10.
23. Common string functions?
strlen, strcpy, strcat, strcmp, strrev (not standard), all in string.h.
24. What is a 2D array?
An array of arrays, like a matrix. Example: int a[3][4] has 3 rows and 4 columns, stored row by row.
Pointers and memory
25. What is a pointer?
A variable that stores the address of another variable. Example: int *p = &x; *p gives the value of x.
26. What is a NULL pointer?
A pointer that points to nothing, set with NULL. Always check for NULL before using a pointer.
27. What is a void pointer?
A generic pointer that can hold the address of any type. It must be cast before you read the value.
28. What is a dangling pointer?
A pointer that still points to memory that has been freed or has gone out of scope. Set it to NULL after free.
29. What is a wild pointer?
A pointer that was never initialised, so it holds a random address.
30. malloc vs calloc?
malloc(size) gives one block with garbage values. calloc(n, size) gives n blocks set to zero.
31. What does realloc do?
Changes the size of memory allocated earlier, keeping the old data.
32. What is a memory leak?
Memory allocated with malloc or calloc that is never freed. The program keeps using more memory over time.
33. What is a pointer to pointer?
A pointer that stores the address of another pointer. Example: int **pp = &p.
Structures and files
34. Structure vs union?
In a structure each member has its own memory, so size is the sum of members (plus padding). In a union all members share one memory location, so size equals the largest member.
35. What is typedef?
It gives a new name to an existing type. Example: typedef struct student Student;
36. What is an enum?
A user-defined type with named integer constants. Example: enum day {MON, TUE, WED}; MON is 0.
37. File opening modes?
“r” read, “w” write (creates or clears), “a” append, plus “r+”, “w+”, “a+” for read and write. Use fopen and fclose.
Output questions
38. What is the output?
int x = 5; printf(“%d”, x++ + ++x);
This is undefined behaviour because x is changed twice without a sequence point. Say this in the interview; it is the answer they want.
39. What is the output?
int a[5] = {1, 2, 3}; printf(“%d”, a[4]);
0. Missing elements in a partly initialised array are set to zero.
40. What is the output?
char *s = “hello”; printf(“%c”, *(s + 1));
e. s + 1 points to the second character.
How to prepare C in 7 days
- Day 1 and 2: data types, operators, loops, functions. Write 10 small programs.
- Day 3 and 4: arrays, strings and pointers. Draw memory boxes for every pointer program.
- Day 5: malloc, calloc, free, structures and unions.
- Day 6: 30 output questions; explain each answer out loud.
- Day 7: revise this list and the OOP list, because many interviews move from C to C++.
Keep preparing
- OOPs interview questions
- DSA interview questions with answers
- Operating System interview questions
- Java interview questions for freshers
- Free notes and Unit 1 of every eBook: Study Material




Doubts? Ask here