๐น C Language Interview Questions & Answers (Top 100)
1. What is C language?
Answer:
C is a procedural, general-purpose programming language developed by Dennis Ritchie in 1972 at Bell Labs. It is fast, efficient, and widely used for system programming.
2. Who developed C language?
Answer:
Dennis Ritchie.
3. What are the features of C?
Answer:
- Simple & efficient
- Portable
- Fast execution
- Structured language
- Rich library
- Supports pointers
4. What is a keyword in C?
Answer:
Keywords are reserved words with predefined meaning in C (e.g., int, return, if).
5. How many keywords are there in C?
Answer:
32 keywords.
6. What is a variable?
Answer:
A variable is a named memory location used to store data.
7. What is data type?
Answer:
Data type specifies the type of data a variable can store.
8. What are basic data types in C?
Answer:
intfloatdoublechar
9. What is sizeof() operator?
Answer:
Returns the size of a data type or variable in bytes.
10. What is constant?
Answer:
A constant is a value that cannot be changed during program execution.
11. What is a pointer?
Answer:
A pointer is a variable that stores the address of another variable.
12. What is NULL pointer?
Answer:
A pointer that does not point to any memory location.
13. What is array?
Answer:
An array is a collection of similar data types stored in contiguous memory.
14. What is string in C?
Answer:
A string is an array of characters ending with '\0'.
15. What is function?
Answer:
A function is a block of code that performs a specific task.
16. What are types of functions?
Answer:
- Library functions
- User-defined functions
17. What is recursion?
Answer:
A function calling itself is called recursion.
18. What is structure?
Answer:
A structure allows storing different data types under one name.
19. What is union?
Answer:
Union stores different data types but shares the same memory location.
20. Difference between structure and union?
Answer:
- Structure uses separate memory
- Union uses shared memory
21. What is enum?
Answer:
Enum is a user-defined data type with named integer constants.
22. What is typedef?
Answer:
Used to create an alias for a data type.
23. What is storage class?
Answer:
Defines scope, lifetime, and visibility of variables.
24. Types of storage classes?
Answer:
- auto
- static
- extern
- register
25. What is static variable?
Answer:
Retains its value between function calls.
26. What is extern keyword?
Answer:
Used to declare a global variable defined elsewhere.
27. What is preprocessor?
Answer:
Processes directives before compilation (e.g., #include, #define).
28. What is macro?
Answer:
A macro is a preprocessor constant.
29. What is header file?
Answer:
Contains function declarations and macros.
30. What is compiler?
Answer:
Converts source code into machine code.
31. What is linker?
Answer:
Links object files to create an executable file.
32. What is break statement?
Answer:
Terminates the loop or switch statement.
33. What is continue statement?
Answer:
Skips current iteration and continues loop.
34. What is goto statement?
Answer:
Transfers control to a labeled statement (not recommended).
35. What is switch statement?
Answer:
Used for multi-way decision making.
36. Difference between while and do-while?
Answer:
while: condition checked firstdo-while: executes at least once
37. What is infinite loop?
Answer:
A loop that never ends.
38. What is pointer arithmetic?
Answer:
Operations performed on pointers (++, –).
39. What is dangling pointer?
Answer:
A pointer pointing to freed memory.
40. What is memory leak?
Answer:
Memory not released after allocation.
41. What is malloc()?
Answer:
Allocates memory dynamically.
42. What is calloc()?
Answer:
Allocates memory and initializes it with zero.
43. Difference between malloc and calloc?
Answer:
- malloc โ no initialization
- calloc โ initializes to zero
44. What is free()?
Answer:
Releases allocated memory.
45. What is segmentation fault?
Answer:
Occurs due to invalid memory access.
46. What is file handling?
Answer:
Reading and writing data to files.
47. Functions used in file handling?
Answer:fopen(), fclose(), fread(), fwrite()
48. What is EOF?
Answer:
End Of File indicator.
49. What is ASCII?
Answer:
American Standard Code for Information Interchange.
50. What is buffering?
Answer:
Temporary storage of data before processing.
51. What is command line argument?
Answer:
Arguments passed to main() during execution.
52. Syntax of main() with arguments?
Answer:int main(int argc, char *argv[])
53. What is volatile keyword?
Answer:
Prevents compiler optimization.
54. What is const keyword?
Answer:
Makes variable read-only.
55. Difference between const and macro?
Answer:
- const โ type checked
- macro โ no type checking
56. What is bitwise operator?
Answer:
Operates on bits (&, |, ^).
57. What is ternary operator?
Answer:
Conditional operator ?:.
58. What is lvalue and rvalue?
Answer:
- lvalue โ addressable
- rvalue โ value only
59. What is recursion base condition?
Answer:
Condition to stop recursion.
60. What is stack?
Answer:
Memory used for function calls.
61. What is heap?
Answer:
Memory used for dynamic allocation.
62. Difference between stack and heap?
Answer:
- Stack โ automatic
- Heap โ manual
63. What is inline function?
Answer:
Function expanded at compile time.
64. What is static function?
Answer:
Accessible only within the file.
65. What is pointer to pointer?
Answer:
Stores address of another pointer.
66. What is array pointer?
Answer:
Pointer pointing to an array.
67. What is self-referential structure?
Answer:
Structure containing pointer to itself.
68. What is linked list?
Answer:
Dynamic data structure using pointers.
69. What is null character?
Answer:'\0' marks end of string.
70. What is difference between char array and string?
Answer:
String ends with \0.
71. What is static memory allocation?
Answer:
Memory allocated at compile time.
72. What is dynamic memory allocation?
Answer:
Memory allocated at runtime.
73. What is scope of variable?
Answer:
Area where variable is accessible.
74. What is global variable?
Answer:
Declared outside all functions.
75. What is local variable?
Answer:
Declared inside a function.
76. What is return statement?
Answer:
Returns value from function.
77. What is void pointer?
Answer:
Generic pointer without data type.
78. What is register keyword?
Answer:
Stores variable in CPU register.
79. What is static array?
Answer:
Array with fixed size.
80. What is dynamic array?
Answer:
Array allocated at runtime.
81. What is typedef struct?
Answer:
Creates alias for structure.
82. What is string.h?
Answer:
Header file for string functions.
83. What is stdio.h?
Answer:
Header file for input/output.
84. What is math.h?
Answer:
Header file for math functions.
85. What is exit()?
Answer:
Terminates program execution.
86. What is assert()?
Answer:
Used for debugging.
87. What is recursion disadvantage?
Answer:
Uses more memory.
88. What is iterative approach?
Answer:
Uses loops instead of recursion.
89. What is dangling pointer issue?
Answer:
Accessing freed memory.
90. What is memory alignment?
Answer:
Proper placement of data in memory.
91. What is padding?
Answer:
Extra bytes added for alignment.
92. What is format specifier?
Answer:
Specifies data type in printf().
93. What is %d?
Answer:
Used for integer.
94. What is %f?
Answer:
Used for float.
95. What is %c?
Answer:
Used for character.
96. What is %s?
Answer:
Used for string.
97. What is scanf()?
Answer:
Reads input from user.
98. What is printf()?
Answer:
Displays output.
99. What is segmentation error?
Answer:
Illegal memory access error.
100. Why is C still popular?
Answer:
Because of speed, portability, low-level control, and system-level programming support.