1. What is a function in C?
A function in C is a self-contained block of code that performs a specific task. It helps in modular programming by dividing a large program into smaller, manageable pieces.
2. Why are functions important in C?
Functions improve code reusability, readability, debugging, and maintenance. They allow developers to avoid repetition of code.
3. What is function declaration?
Function declaration (also called prototype) informs the compiler about the function name, return type, and parameters before its actual definition.
4. What is function definition?
Function definition contains the actual body of the function where logic is written.
5. What is function call?
Function call is the process of invoking or executing the function by using its name followed by arguments.
6. What is a function prototype?
A function prototype specifies the return type and parameters. It ensures type checking during compilation.
7. What is the difference between declaration and definition?
Declaration only informs about the function, whereas definition provides the implementation.
8. What are actual parameters?
Actual parameters are the values passed to the function during function call.
9. What are formal parameters?
Formal parameters are variables defined in the function definition to receive values.
10. What happens if function prototype is not declared?
The compiler may assume default return type (int in old C versions), which can cause errors or unexpected behavior.
11. What is call by value?
In call by value, a copy of actual argument is passed. Changes inside the function do not affect original value.
12. What is call by reference?
In call by reference, address of variable is passed using pointers. Changes affect original variable.
13. How does C implement call by reference?
C uses pointers to simulate call by reference.
14. What is parameter passing mechanism in C?
C uses call by value by default.
15. What is default argument in C?
C does not support default arguments (unlike C++).
16. What are variable length arguments?
Using stdarg.h, functions can accept variable number of arguments.
17. What is argument type mismatch?
If argument types do not match prototype, it leads to compilation error or undefined behavior.
18. Can we pass arrays to functions?
Yes, arrays are passed as pointers to functions.
19. Can structures be passed to functions?
Yes, structures can be passed by value or by pointer.
20. What is const parameter?
const ensures that parameter value cannot be modified inside function.
21. What is scope of a variable?
Scope defines the region in which a variable is accessible.
22. What is local scope?
Variables declared inside function are local to that function.
23. What is global scope?
Variables declared outside all functions are global and accessible throughout file.
24. What is block scope?
Variables declared inside a block {} are accessible only within that block.
25. What is static variable in function?
Static variable retains its value between function calls.
26. What is register storage class?
Suggests compiler to store variable in CPU register for fast access.
27. What is extern keyword?
extern is used to declare global variable in another file.
28. What is lifetime of local variable?
It exists only during function execution.
29. What is lifetime of global variable?
It exists throughout program execution.
30. Can local variable have same name as global?
Yes, local variable shadows global variable within its scope.
31. What is pointer to function?
A pointer to function stores address of a function.
32. Why use function pointers?
They allow dynamic function calls and are used in callbacks.
33. How to declare function pointer?
int (*ptr)(int, int);
34. How to assign function to pointer?
ptr = add;
35. How to call function using pointer?
(*ptr)(a, b);
36. What is callback function?
A function passed as argument to another function.
37. Where are function pointers used?
Used in event handling, interrupt handling, and sorting functions like qsort().
38. Can function pointer return another function pointer?
Yes, but syntax becomes complex.
39. What is array of function pointers?
An array storing multiple function addresses.
40. Difference between normal pointer and function pointer?
Normal pointer stores data address; function pointer stores function address.
41. What is recursion?
When function calls itself to solve smaller subproblems.
42. What is base condition in recursion?
Stopping condition to prevent infinite recursion.
43. What is stack overflow?
Occurs when too many recursive calls exceed stack memory.
44. What is inline function?
Suggested to compiler to replace function call with function body.
45. What is tail recursion?
Recursive call is last statement in function.
46. Can main() call itself?
Yes, but not recommended.
47. What is nested function?
C does not support nested functions (except GCC extension).
48. What is function overloading?
C does not support function overloading.
49. What is function overriding?
C does not support overriding as it lacks OOP.
50. What are common challenges with functions?
Improper scope handling, stack overflow in recursion, incorrect pointer usage, memory leaks, and mismatched prototypes are common challenges.
📢 Join Our WhatsApp Channel
💼 Get Daily IT Job Updates, Interview Preparation Tips & Instant Alerts directly on WhatsApp.
👉 Join WhatsApp Now📢 Join Our Telegram Channel
💼 Get Daily IT Job Updates, Interview Tips & Exclusive Alerts directly on Telegram!
👉 Join Telegram