C Programming FAQs – 165 Interview Questions and Answers for Freshers
120 Technical FAQs • 15 Output-Based Questions • 30 Coding Exercises
C is a general-purpose procedural programming language widely used in operating systems, embedded systems and application development. This guide helps B.Tech, B.Sc., BCA, MCA students and freshers prepare for campus placements and technical interviews.
1. C Programming Fundamentals
1. What is C programming?
C is a general-purpose, procedural programming language developed by Dennis Ritchie at Bell Labs in the early 1970s.
2. What are the main features of C?
Portability, efficiency, structured programming, pointers, recursion, dynamic memory allocation and low-level memory access.
3. Why is C called a middle-level language?
It combines high-level control structures and functions with low-level memory access.
4. Is C compiled or interpreted?
C is typically compiled into machine code before execution.
5. What is the basic structure of a C program?
A program contains header inclusions, functions, declarations and executable statements.
#include <stdio.h>
int main(void) {
printf("Hello, World!");
return 0;
}
6. What is the purpose of main()?
It is the entry point in a hosted C environment.
7. What is a header file?
A header contains declarations, macros and type definitions. Examples include stdio.h, stdlib.h, string.h and math.h.
8. What are tokens?
The smallest lexical units: keywords, identifiers, constants, string literals and punctuators.
9. What are keywords?
Reserved words such as int, if, return and struct. C90 has 32 keywords; later standards add more.
10. What is an identifier?
A name given to a program entity, such as totalMarks or calculateSalary.
2. Variables, Constants and Data Types
11. What is a variable?
A named object used to store a value.
int age = 21;
12. What are the basic data types?
char, int, float, double and void. Typical sizes are 1, 4, 4 and 8 bytes respectively for the first four; actual sizes depend on the implementation.
13. What is a constant?
A fixed value. The const qualifier can also declare read-only objects.
const float PI = 3.14159f;
14. What is the difference between declaration and initialization?
Declaration introduces a name and type; initialization supplies an initial value.
int a;
int b = 10;
15. What is the difference between local and global variables?
Local variables have block scope and usually automatic storage duration. Global variables have file scope and static storage duration and are zero-initialized by default.
16. What is type casting?
Explicit conversion between types.
float result = (float)5 / 2;
17. What is sizeof?
An operator returning the size of an object or type in bytes.
printf("%zu", sizeof(int));
18. What are format specifiers?
They specify types for formatted I/O: %d for int, %f for floating-point output, %lf for double input, %c for character, %s for string, %p for void pointer and %zu for size_t.
19. What is the difference between signed and unsigned integers?
Signed integers represent negative and positive values and zero; unsigned integers represent nonnegative values.
20. What is the difference between const and #define?
const qualifies a typed object; #define performs preprocessing token substitution.
3. Operators and Expressions
21. What are the types of operators?
Arithmetic, relational, logical, assignment, increment/decrement, bitwise, conditional and special operators.
22. What is the difference between = and ==?
= assigns a value; == compares values for equality.
23. What is the difference between ++i and i++?
Prefix increment produces the incremented value; postfix increment produces the original value and increments the object.
24. What is the ternary operator?
A conditional expression that selects one of two operands.
int max = (a > b) ? a : b;
25. What is the modulus operator?
% returns the remainder of integer division. 10 % 3 is 1.
26. What are bitwise operators?
They operate on integer bits: &, |, ^, ~, << and >>.
27. What is operator precedence?
Rules determining expression grouping. For example, 5 + 3 * 2 evaluates to 11.
28. What is short-circuit evaluation?
The second operand of && or || is skipped when the first determines the result.
if (b != 0 && a / b > 2) { printf("True"); }
4. Control Statements and Loops
29. What are control statements?
Statements controlling execution flow, including decisions, loops and jumps.
30. What is the difference between if-else and switch?
if-else supports complex conditions and ranges; switch compares an integer expression with constant case values.
31. What loops does C support?
for, while and do-while.
32. What is the difference between while and do-while?
while tests before the body; do-while tests afterward and executes at least once.
33. What is an infinite loop?
A loop without normal termination.
while (1) { printf("Running"); }
34. What is the difference between break and continue?
break exits the nearest loop or switch; continue skips to the next loop iteration.
35. What is a nested loop?
A loop inside another loop.
36. What is goto?
A statement transferring control to a label within the same function.
5. Functions and Recursion
37. What is a function?
A reusable block of code performing a task.
int add(int a, int b) { return a + b; }
38. What are the types of functions?
Standard library functions and user-defined functions.
39. What is a function prototype?
A declaration specifying the function name, return type and parameter types.
int add(int, int);
40. What are actual and formal parameters?
Actual arguments are supplied at a call; formal parameters are declared in the function definition.
41. What is call by value versus call by reference?
C passes all arguments by value. Passing a pointer allows modification of the pointed-to object, providing reference-like behavior.
42. What is recursion?
A function calling itself directly or indirectly.
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
43. What is a base condition?
A condition that terminates recursive calls.
44. What is the difference between recursion and iteration?
Recursion uses function calls and typically additional stack memory; iteration uses loops.
45. Can a function return multiple values?
It directly returns one value, but pointers or a structure can convey multiple results.
6. Arrays and Strings
46. What is an array?
A collection of same-type elements in contiguous memory.
int marks[5] = {80, 90, 75, 85, 95};
47. Why does array indexing start at zero?
An index represents an offset from the first element.
48. What are the types of arrays?
One-dimensional, two-dimensional and multidimensional arrays.
49. What is a two-dimensional array?
An array of arrays, commonly representing rows and columns.
int matrix[2][2] = {{1, 2}, {3, 4}};
50. What happens when an array is accessed out of bounds?
Undefined behavior, potentially causing corruption or crashes.
51. What is a string?
A character sequence terminated by the null character.
char name[] = "Hello";
52. What are common string functions?
strlen, strcpy, strcat, strcmp, strchr and strstr, declared in string.h.
53. What is the difference between strlen and sizeof?
strlen counts characters before the null terminator; sizeof returns object size in bytes. For char str[] = "Hello", the results are 5 and 6.
54. What is the difference between a character array and a string?
A character array need not contain a null terminator; a C string must.
55. Why should gets() not be used?
It cannot limit input to buffer capacity and was removed in C11. Use fgets instead.
char name[50];
fgets(name, sizeof(name), stdin);
56. What is the difference between scanf and fgets?
scanf with %s stops at whitespace; fgets reads spaces and limits input to the supplied buffer size.
7. Pointers
57. What is a pointer?
An object storing an address.
int a = 10;
int *ptr = &a;
58. What are the advantages of pointers?
They enable dynamic allocation, data structures, array processing and reference-like behavior.
59. What is the difference between & and *?
Unary & obtains an address; unary * dereferences a pointer.
60. What is a NULL pointer?
A pointer that does not point to an object or function.
int *ptr = NULL;
61. What is a dangling pointer?
A pointer referring to an object whose lifetime has ended.
62. What is a wild pointer?
An informal term for an uninitialized pointer with an indeterminate value.
63. What is a void pointer?
A generic object pointer that can be converted to and from other object pointer types.
64. What is a pointer to a pointer?
A pointer storing the address of another pointer.
int a = 10;
int *p = &a;
int **q = &p;
65. What is pointer arithmetic?
Arithmetic on pointers within the permitted bounds of an array, including its one-past position.
66. What is the difference between an array and a pointer?
An array contains elements; a pointer stores an address. sizeof an actual array returns its total size, while sizeof a pointer returns pointer size.
67. What is a function pointer?
A pointer allowing indirect function calls, commonly used for callbacks.
int (*operation)(int, int) = add;
8. Dynamic Memory Allocation
68. What is dynamic memory allocation?
Allocating memory during execution using standard library functions.
69. What are the allocation functions?
malloc, calloc, realloc and free, declared in stdlib.h.
70. What is the difference between malloc and calloc?
malloc takes a byte count and leaves memory uninitialized; calloc takes element count and size and initializes bytes to zero.
71. What is realloc?
A function resizing an allocated block, potentially moving it. On failure for a nonzero size, the original block remains allocated.
72. What is a memory leak?
Allocated memory that is no longer needed but has not been released.
73. What is the difference between stack and heap?
Typical implementations use the stack for automatic local objects and calls, and the heap for dynamically allocated objects. Actual layouts are platform-dependent.
74. What happens if malloc fails?
It returns a null pointer.
int *p = malloc(5 * sizeof *p);
if (p == NULL) { printf("Allocation failed"); }
75. What is a double-free error?
Freeing the same allocation twice, resulting in undefined behavior.
9. Structures, Unions and Enumerations
76. What is a structure?
A type grouping related members of potentially different types.
struct Student { int rollNo; char name[50]; float marks; };
77. What is a union?
A type whose members share storage.
union Data { int i; float f; char ch; };
78. What is the difference between structure and union?
Structure members have separate storage; union members share storage sized and aligned to accommodate all members.
79. What is an enumeration?
A type introducing named integer constants.
enum Day { MON, TUE, WED, THU, FRI };
80. What is typedef?
A declaration introducing an alternative name for a type.
typedef unsigned int uint;
81. What is a nested structure?
A structure containing another structure as a member.
82. What is a self-referential structure?
A structure containing a pointer to its own type.
struct Node { int data; struct Node *next; };
83. What is the difference between . and ->?
The dot accesses members of an object; the arrow accesses members through a pointer.
84. What is structure padding?
Extra bytes inserted to satisfy alignment requirements.
10. Storage Classes and Preprocessor Directives
85. What are storage classes?
Traditionally taught specifiers include auto, register, static and extern, affecting storage duration or linkage.
86. What is a static variable?
A static local variable retains its value between function calls.
void counter(void) { static int count = 0; printf("%d ", ++count); }
87. What is extern?
A specifier commonly used to declare an object or function defined elsewhere.
88. What is register?
A traditional hint for frequent access; it does not guarantee CPU register storage.
89. What is a preprocessor directive?
An instruction processed before compilation, such as #include or #define.
90. What is a macro?
A named preprocessing replacement.
#define SQUARE(x) ((x) * (x))
91. What is the difference between a macro and a function?
Macros expand tokens and may evaluate arguments repeatedly; functions have typed parameters and evaluate each argument expression once per call.
92. What is conditional compilation?
Compiling selected code based on preprocessing conditions.
#ifdef DEBUG
printf("Debug mode");
#endif
11. File Handling
93. What is file handling?
Creating, reading, writing and manipulating files.
94. What is a FILE pointer?
A pointer to a stream object used by standard I/O functions.
FILE *fp;
95. What are file opening modes?
r reads, w writes or truncates, a appends; r+, w+, a+ allow updates; b selects binary mode.
96. What are common file functions?
fopen, fclose, fprintf, fscanf, fgets, fputs, fread, fwrite, fseek, ftell and rewind.
97. What is the difference between text and binary files?
Text streams represent characters and may translate line endings; binary streams preserve byte data without text-mode transformations.
98. What is EOF?
A negative integer constant indicating end-of-file or input failure in certain input functions.
99. How do you check if a file opened successfully?
Check whether fopen returned NULL.
FILE *fp = fopen("data.txt", "r");
if (fp == NULL) printf("Unable to open file");
else fclose(fp);
100. Why is fclose important?
It closes a stream, flushes buffered output and releases associated resources.
12. Advanced and Industry-Oriented FAQs
101. What are the types of errors?
Syntax, compilation, linker, runtime and logical errors.
102. What is a segmentation fault?
An operating-system error commonly caused by invalid memory access.
103. What is undefined behavior?
Behavior for which the C standard imposes no requirements, such as signed integer overflow or invalid pointer dereferencing.
104. What is a buffer overflow?
Writing beyond a buffer's capacity, potentially corrupting memory.
105. What is volatile?
A qualifier indicating accesses may have externally observable effects. It is useful for hardware registers but does not provide thread synchronization.
106. What is the difference between compiler and linker?
A compiler translates source code; a linker combines object files and libraries and resolves references.
107. What are the stages of compilation?
Preprocessing, compilation, assembly and linking, producing an executable in a typical toolchain.
108. What are command-line arguments?
Values supplied when launching a program. argc counts arguments and argv contains argument strings.
int main(int argc, char *argv[]) { return 0; }
109. What is the difference between C and C++?
C is primarily procedural; C++ additionally supports classes, templates, exceptions, overloading and RAII.
110. Is C object-oriented?
It lacks built-in classes and inheritance, but structures and function pointers can implement similar patterns.
111. What is modular programming?
Dividing software into smaller reusable components.
112. What is debugging?
Identifying and correcting errors using tools such as GDB or LLDB.
113. What is a library?
A collection of reusable program components, often packaged as static or shared libraries.
114. What is static versus dynamic linking?
Static linking incorporates library code into the executable; dynamic linking resolves shared libraries during loading or execution.
115. What is an API?
An interface defining functions, types and conventions for software interaction.
116. What is a callback?
A function passed to another function, typically through a function pointer, for later invocation.
117. What is a race condition?
A condition where correctness depends on the timing or ordering of concurrent operations.
118. What is shallow versus deep copy?
Shallow copying copies pointer values; deep copying also creates independent copies of referenced data.
119. Where is C used in industry?
Operating systems, embedded systems, IoT, drivers, databases, compilers, networking, robotics and high-performance computing.
120. Why should freshers learn C?
It builds foundations in logic, algorithms, data structures, memory management and computer architecture.
13. Output-Based Interview Questions
Predict the output before revealing the answer. Assume required headers and an enclosing function are present.
121. What is the output?
int a = 5, b = 2;
printf("%d", a / b);
Show answer and explanation
2 — Integer division discards the fractional part.
122. What is the output?
int a = 10;
printf("%d", a++);
Show answer and explanation
10 — Postfix increment produces the original value.
123. What is the output?
int a = 10;
printf("%d", ++a);
Show answer and explanation
11 — Prefix increment produces the incremented value.
124. What is the output?
printf("%d", 17 % 5);
Show answer and explanation
2 — The remainder is 2.
125. What is the output?
int a[] = {10, 20, 30, 40};
printf("%d", a[2]);
Show answer and explanation
30 — Indexing starts at zero.
126. What is the output?
char str[] = "Programming";
printf("%zu", strlen(str));
Show answer and explanation
11 — strlen excludes the terminator.
127. What is the output?
char str[] = "Hello";
printf("%zu", sizeof(str));
Show answer and explanation
6 — Includes the null terminator.
128. What is the output?
for (int i = 1; i <= 5; i++) printf("%d ", i);
Show answer and explanation
1 2 3 4 5 — Five iterations.
129. What is the output?
int a = 25;
int *p = &a;
*p = 50;
printf("%d", a);
Show answer and explanation
50 — The pointer modifies a.
130. What is the output?
int a = 10, b = 20;
printf("%d", a > b ? a : b);
Show answer and explanation
20 — The false branch is selected.
131. What is the output?
printf("%d", 5 & 3);
Show answer and explanation
1 — Bitwise AND produces 0001.
132. What is the output?
printf("%d", 10 && 20);
Show answer and explanation
1 — Both operands are nonzero.
133. What is the output?
printf("%c", 'A' + 1);
Show answer and explanation
B (ASCII-compatible systems) — B follows A in ASCII.
134. What is the output?
int i = 10;
do { printf("%d", i); } while (i < 5);
Show answer and explanation
10 — The body executes once.
135. What is the output?
int i = 5;
printf("%d %d", i++, ++i);
Show answer and explanation
Undefined behavior — The modifications are unsequenced.
14. Top 30 Practical Coding Questions
Basic Programming
- Check even or odd.
- Find largest of three numbers.
- Swap two numbers with and without a temporary variable.
- Calculate factorial.
- Generate Fibonacci series.
- Check prime number.
- Check numeric palindrome.
- Check Armstrong number.
- Reverse a number.
- Find sum of digits.
Arrays and Strings
- Find largest and smallest array elements.
- Find second-largest distinct element.
- Implement bubble sort.
- Implement linear search.
- Implement binary search.
- Remove duplicate array elements.
- Find missing number from 1 to N.
- Reverse a string without library functions.
- Check string palindrome.
- Count vowels, consonants and digits.
Advanced Programming
- Calculate factorial using recursion.
- Find GCD and LCM.
- Perform matrix addition and multiplication.
- Swap numbers using pointers.
- Allocate an array dynamically.
- Store student details using structures.
- Count set bits.
- Implement a singly linked list.
- Implement a stack and queue.
- Read and write student records using files.
15. Placement Preparation Priorities
| Topic | Suggested priority |
|---|---|
| Functions, loops and recursion | Very High |
| Arrays, strings and pointers | Very High |
| Dynamic memory and data structures | Very High |
| Output-based and logical programming | Very High |
| Fundamentals, operators and data types | High |
| Structures, unions and storage classes | High |
| File handling and debugging | High |
| Preprocessor directives | Medium |
These are suggested study priorities, not measured interview statistics.
Conclusion
C builds a strong foundation in programming, problem-solving and memory management. Practice writing programs, predicting outputs and debugging errors alongside theoretical preparation.
Recommended for: B.Tech CSE, AI & ML, IT, ECE, B.Sc. Computer Science, BCA, MCA students and freshers.