Entrance Exams
Govt. Exams
A static function has internal linkage and is limited to the file in which it is defined. It cannot be accessed from other translation units.
A function prototype must have the return type first, followed by the function name and parameter list in parentheses. Option A is the correct syntax.
int counter = 0;
void increment() { static int count = 0; count++; counter++; }
main() { increment(); increment(); printf("%d %d", count, counter); }
The static variable 'count' is local to increment() and inaccessible from main(). Trying to print 'count' causes compilation error: undefined identifier.
Variadic functions use ... syntax, and at least one named parameter must precede it. Option A is correct; Option B violates requirement of at least one named parameter.
Variadic functions (using ...) don't validate argument count. Calling with fewer arguments leads to undefined behavior as the function reads undefined values from stack.
In void functions, return statement (without value) can be used to exit the function prematurely. It's optional at the end since function exits automatically.
int x = 10;
int* getAddress() { return &x; }
main() { int *ptr = getAddress(); printf("%d", *ptr); }
Since x is static (global scope), returning its address is safe and the pointer remains valid. The output is 10. If x were local, it would be undefined behavior.
Both approaches are valid in C: returning a struct with multiple fields or using pointers as output parameters. Using globals is possible but not recommended.
The restrict keyword (C99) is a promise to the compiler that the pointer is the only way to access that memory during its lifetime, allowing aggressive optimizations.
Array names decay to pointers in function calls. The parameter arr receives the address of the first element, so modifications affect the original array.