Govt. Exams
Entrance Exams
Functions can have multiple forward declarations but only one definition. This allows function prototypes in header files.
A callback function is a function pointer passed to another function, which calls it at a later point in time.
Without an explicit return statement, the function returns whatever value is in the return register, which is undefined behavior.
A static function has file scope and cannot be accessed from other translation units, providing encapsulation.
Variadic functions require at least one named parameter before the ellipsis. Both options B and C follow the correct syntax.
void func(int arr[10]) { printf("%lu", sizeof(arr)); }
int main() { int a[10]; func(a); }
When arrays are passed to functions, they decay to pointers. sizeof(arr) returns the size of the pointer, not the array.
Old-style K&R C declarations don't perform argument checking, allowing calls with fewer arguments. Modern prototyped functions generate compiler errors.
The correct syntax for function pointer is return_type (*pointer_name)(parameter_types). Option A is correct.
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.