Govt Exams
strlen() returns size_t, which is an unsigned integer type used to represent sizes and counts in C.
C does not support function overloading. To achieve similar functionality, use different names or variadic functions (using ...) or union of function pointers.
The 'inline' keyword is a hint to the compiler to replace function calls with the function body, reducing overhead but increasing code size.
int counter() { static int count = 0; return ++count; }
int main() { printf("%d ", counter()); printf("%d ", counter()); printf("%d", counter()); }
Static variable 'count' retains its value. First call: 0+1=1, second: 1+1=2, third: 2+1=3.
Static local variables retain their value between function calls, initialized only once, and are stored in data segment.
int* getPointer(int *p) { return p; }
int main() { int a = 10; int *ptr = getPointer(&a); printf("%d", *ptr); }
The function receives the address of 'a', returns it, and dereferencing gives 10. However, returning pointers to local variables is risky in other contexts.
All three methods work: return value, pass pointers, or use global variables. Each has different use cases and implications.
void modify(int x) { x = x + 10; }
int main() { int a = 5; modify(a); printf("%d", a); }
Since parameters are passed by value, changes to 'x' inside modify() don't affect 'a' in main(). Output is 5.
C passes parameters by value by default. To achieve pass-by-reference effect, pointers must be used explicitly.
int factorial(int n) { return n * factorial(n-1); }
The recursive function lacks a base case (like if n==0 return 1) to terminate recursion, causing infinite recursion and stack overflow.