Govt Exams
Inline functions request the compiler to replace function calls with actual function code, eliminating call overhead. However, compiler may ignore inline suggestion.
Function pointers are powerful features enabling dynamic function selection at runtime, crucial for callbacks, function arrays, and design patterns like strategy pattern.
int fact(int n) { if(n
fact(4) = 4*fact(3) = 4*3*fact(2) = 4*3*2*fact(1) = 4*3*2*1 = 24. This is a proper factorial implementation with correct base case.
The parentheses around (*ptr) indicate ptr is a pointer. The remaining (int, int) shows it points to a function taking two int arguments and returning int.
C supports call by value (default) and call by reference (using pointers). Call by value passes a copy; call by reference passes the address allowing modifications to original.
int add(int a, int b) { return a + b; }
int main() { printf("%d", add(5, add(3, 2))); return 0; }
Inner add(3,2) returns 5, then add(5,5) returns 10. Functions can be nested in arguments as long as return type matches parameter type.
The cdecl (C declaration) calling convention is the standard in C, pushing parameters onto the stack from right to left, with the caller responsible for stack cleanup.
Static variables inside a function have local scope but static storage duration, meaning they retain their value between function calls and are initialized only once.
The C standard does not impose a maximum limit on the number of function parameters, though practical implementations may have compiler-specific limits.
If a non-void function doesn't explicitly return a value, it returns whatever garbage value happens to be in the return register, leading to undefined behavior.