C Programming (Basic to Advanced) – Interview Questions

Practice interview questions by difficulty level

Showing: All Questions
Q1. What is C language?
Beginner Level
C is a general-purpose procedural programming language used for system and application software.
Q2. Who developed the C language?
Beginner Level
C language was developed by Dennis Ritchie at Bell Labs.
Q3. What is the use of main() function in C?
Beginner Level
main() is the entry point of every C program where execution starts.
Q4. What is a variable in C?
Beginner Level
A variable is a named memory location used to store data.
Q5. What are keywords in C?
Beginner Level
Keywords are reserved words with predefined meanings in C.
Q6. What is a data type?
Beginner Level
A data type specifies the type of data a variable can hold.
Q7. Name basic data types in C.
Beginner Level
int, float, char, and double are basic data types in C.
Q8. What is a constant?
Beginner Level
A constant is a fixed value that cannot be changed during program execution.
Q9. What is printf() function?
Beginner Level
printf() is used to display output on the screen.
Q10. What is scanf() function?
Beginner Level
scanf() is used to take input from the user.
Q11. What is a header file?
Beginner Level
A header file contains function declarations and macros.
Q12. What is #include in C?
Beginner Level
#include is a preprocessor directive used to include header files.
Q13. What are comments in C?
Beginner Level
Comments are used to explain code and are ignored by the compiler.
Q14. What is an operator?
Beginner Level
An operator performs operations on variables and values.
Q15. What is an expression?
Beginner Level
An expression is a combination of variables, constants, and operators.
Q16. What is a function?
Beginner Level
A function is a block of code that performs a specific task.
Q17. What is return statement?
Beginner Level
return sends a value back from a function to the calling program.
Q18. What is an array?
Beginner Level
An array stores multiple values of the same data type in contiguous memory.
Q19. What is a loop?
Beginner Level
A loop executes a block of code repeatedly based on a condition.
Q20. Name loop types in C.
Beginner Level
for, while, and do-while are loop types in C.
Q21. What is a pointer in C?
Intermediate Level
A pointer stores the memory address of another variable.
Q22. What is an array in C?
Intermediate Level
An array stores multiple elements of the same data type in contiguous memory locations.
Q23. Difference between array and pointer?
Intermediate Level
Array stores elements, while pointer stores memory addresses.
Q24. What is recursion?
Intermediate Level
Recursion is a function calling itself until a base condition is met.
Q25. What is a structure?
Intermediate Level
A structure is a user-defined data type that groups variables of different data types.
Q26. Difference between structure and union?
Intermediate Level
Structure allocates separate memory for members, union shares the same memory.
Q27. What is a function prototype?
Intermediate Level
A function prototype declares a function before it is used.
Q28. What is call by value?
Intermediate Level
In call by value, a copy of actual parameter is passed to function.
Q29. What is call by reference?
Intermediate Level
In call by reference, address of actual parameter is passed to function.
Q30. What are storage classes in C?
Intermediate Level
auto, register, static, and extern define variable scope and lifetime.
Q31. What is static variable?
Intermediate Level
A static variable retains its value between function calls.
Q32. What is extern keyword?
Intermediate Level
extern allows a variable to be accessed across multiple files.
Q33. What is dynamic memory allocation?
Intermediate Level
It allocates memory at runtime using functions like malloc and calloc.
Q34. Difference between malloc() and calloc()?
Intermediate Level
malloc allocates uninitialized memory; calloc initializes memory to zero.
Q35. What is free() function?
Intermediate Level
free() releases dynamically allocated memory.
Q36. What is a pointer to pointer?
Intermediate Level
It is a pointer that stores the address of another pointer.
Q37. What is file handling in C?
Intermediate Level
File handling allows reading and writing data to files.
Q38. What is fopen()?
Intermediate Level
fopen() opens a file in specified mode.
Q39. Difference between fscanf() and fprintf()?
Intermediate Level
fscanf reads data from file; fprintf writes data to file.
Q40. What is preprocessor?
Intermediate Level
Preprocessor handles directives before compilation.
Q41. What is macro?
Intermediate Level
A macro is a preprocessor definition that replaces code textually.
Q42. Difference between macro and function?
Intermediate Level
Macro is expanded at compile time; function executes at runtime.
Q43. What is typedef?
Intermediate Level
typedef creates an alias name for existing data types.
Q44. What is const keyword?
Intermediate Level
const makes a variable read-only.
Q45. Difference between const and #define?
Intermediate Level
const has type checking; #define does not.
Q46. What is string in C?
Intermediate Level
A string is an array of characters ending with a null character.
Q47. What is strlen()?
Intermediate Level
strlen() returns the length of a string excluding null character.
Q48. What is strcmp()?
Intermediate Level
strcmp() compares two strings lexicographically.
Q49. What is segmentation fault?
Intermediate Level
It occurs when a program accesses invalid memory.
Q50. What is memory leak?
Intermediate Level
Memory leak occurs when allocated memory is not freed.
Q51. What is a dangling pointer?
Advanced Level
A pointer that points to memory that has already been freed.
Q52. What is a void pointer?
Advanced Level
A void pointer can hold the address of any data type but must be typecast before use.
Q53. Explain volatile keyword.
Advanced Level
volatile prevents compiler optimizations for variables that can change unexpectedly.
Q54. Difference between stack and heap memory?
Advanced Level
Stack is automatic and fast; heap is dynamic and manually managed.
Q55. What is memory alignment?
Advanced Level
Memory alignment ensures data is stored at addresses suitable for the CPU architecture.
Q56. What is strict aliasing rule?
Advanced Level
It restricts accessing an object through incompatible pointer types to allow optimization.
Q57. What is undefined behavior in C?
Advanced Level
Behavior not defined by the C standard, leading to unpredictable results.
Q58. What is inline function?
Advanced Level
inline suggests the compiler to expand the function code at call sites.
Q59. Explain const correctness.
Advanced Level
Ensuring variables and pointers are correctly declared const to prevent modification.
Q60. What is a function pointer?
Advanced Level
A pointer that stores the address of a function and can invoke it.
Q61. What is reentrancy?
Advanced Level
A function is reentrant if it can be safely interrupted and re-entered.
Q62. Difference between deep copy and shallow copy?
Advanced Level
Deep copy duplicates memory; shallow copy copies references only.
Q63. What is bitwise operation?
Advanced Level
Operations that manipulate individual bits of data.
Q64. What is endianness?
Advanced Level
Byte order used to represent multi-byte data types in memory.
Q65. Difference between little endian and big endian?
Advanced Level
Little endian stores least significant byte first; big endian stores most significant byte first.
Q66. What is memory fragmentation?
Advanced Level
Inefficient use of memory due to scattered free blocks.
Q67. What is setjmp and longjmp?
Advanced Level
Used for non-local jumps to restore execution context.
Q68. Explain signal handling in C.
Advanced Level
Signals are asynchronous events handled using signal handlers.
Q69. What is race condition?
Advanced Level
Occurs when multiple processes access shared data simultaneously causing inconsistency.
Q70. What is thread safety?
Advanced Level
Ensuring correct behavior when code is accessed by multiple threads.
Q71. Difference between memcpy and memmove?
Advanced Level
memcpy is unsafe for overlapping memory; memmove handles overlap safely.
Q72. What is static linking?
Advanced Level
All library code is included at compile time.
Q73. What is dynamic linking?
Advanced Level
Libraries are linked at runtime, reducing executable size.
Q74. What is position-independent code?
Advanced Level
Code that executes correctly regardless of its memory address.
Q75. Explain segmentation fault causes.
Advanced Level
Caused by invalid memory access such as NULL or out-of-bounds pointers.
Q76. What is compiler optimization?
Advanced Level
Techniques used by compiler to improve performance and reduce code size.
Q77. What is buffer overflow?
Advanced Level
Writing data beyond allocated buffer limits.
Q78. Difference between exit() and _exit()?
Advanced Level
exit performs cleanup; _exit terminates immediately.
Q79. What is ABI?
Advanced Level
Application Binary Interface defines how binaries interact at runtime.
Q80. Explain multi-file programming in C.
Advanced Level
Using multiple source and header files for modular code.
Q81. What is a dangling pointer?
Advanced Level
A pointer that points to memory that has already been freed.
Q82. What is a void pointer?
Advanced Level
A void pointer can hold the address of any data type but must be typecast before use.
Q83. Explain volatile keyword.
Advanced Level
volatile prevents compiler optimizations for variables that can change unexpectedly.
Q84. Difference between stack and heap memory?
Advanced Level
Stack is automatic and fast; heap is dynamic and manually managed.
Q85. What is memory alignment?
Advanced Level
Memory alignment ensures data is stored at addresses suitable for the CPU architecture.
Q86. What is strict aliasing rule?
Advanced Level
It restricts accessing an object through incompatible pointer types to allow optimization.
Q87. What is undefined behavior in C?
Advanced Level
Behavior not defined by the C standard, leading to unpredictable results.
Q88. What is inline function?
Advanced Level
inline suggests the compiler to expand the function code at call sites.
Q89. Explain const correctness.
Advanced Level
Ensuring variables and pointers are correctly declared const to prevent modification.
Q90. What is a function pointer?
Advanced Level
A pointer that stores the address of a function and can invoke it.
Q91. What is reentrancy?
Advanced Level
A function is reentrant if it can be safely interrupted and re-entered.
Q92. Difference between deep copy and shallow copy?
Advanced Level
Deep copy duplicates memory; shallow copy copies references only.
Q93. What is bitwise operation?
Advanced Level
Operations that manipulate individual bits of data.
Q94. What is endianness?
Advanced Level
Byte order used to represent multi-byte data types in memory.
Q95. Difference between little endian and big endian?
Advanced Level
Little endian stores least significant byte first; big endian stores most significant byte first.
Q96. What is memory fragmentation?
Advanced Level
Inefficient use of memory due to scattered free blocks.
Q97. What is setjmp and longjmp?
Advanced Level
Used for non-local jumps to restore execution context.
Q98. Explain signal handling in C.
Advanced Level
Signals are asynchronous events handled using signal handlers.
Q99. What is race condition?
Advanced Level
Occurs when multiple processes access shared data simultaneously causing inconsistency.
Q100. What is thread safety?
Advanced Level
Ensuring correct behavior when code is accessed by multiple threads.
Q101. Difference between memcpy and memmove?
Advanced Level
memcpy is unsafe for overlapping memory; memmove handles overlap safely.
Q102. What is static linking?
Advanced Level
All library code is included at compile time.
Q103. What is dynamic linking?
Advanced Level
Libraries are linked at runtime, reducing executable size.
Q104. What is position-independent code?
Advanced Level
Code that executes correctly regardless of its memory address.
Q105. Explain segmentation fault causes.
Advanced Level
Caused by invalid memory access such as NULL or out-of-bounds pointers.
Q106. What is compiler optimization?
Advanced Level
Techniques used by compiler to improve performance and reduce code size.
Q107. What is buffer overflow?
Advanced Level
Writing data beyond allocated buffer limits.
Q108. Difference between exit() and _exit()?
Advanced Level
exit performs cleanup; _exit terminates immediately.
Q109. What is ABI?
Advanced Level
Application Binary Interface defines how binaries interact at runtime.
Q110. Explain multi-file programming in C.
Advanced Level
Using multiple source and header files for modular code.