Govt Exams
The volatile keyword tells the compiler not to optimize away variable accesses, ensuring the variable is read from memory each time.
Function pointers enable runtime polymorphism by allowing selection of which function to call based on runtime conditions.
While C99 guarantees support for at least 127 parameters, the actual limit is implementation-dependent and varies by compiler.
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.
int sum = 0;
for(int i = 1; i
The loop adds only odd numbers (1,3,5,7,9) due to the continue statement when i is even. Sum = 1+3+5+7+9 = 25.