How does C pass arguments to a function?
Every argument is copied into the parameter. Passing a pointer copies the address, which is how a function can change the caller's data; an array argument is converted to a pointer to its first element first.
Functions · Exercise 1 of 4
Twelve multiple-choice questions on prototypes, pass by value, static, recursion, inline functions and what C99 and C23 changed. Pick an option to check your answer instantly.
How does C pass arguments to a function?
Every argument is copied into the parameter. Passing a pointer copies the address, which is how a function can change the caller's data; an array argument is converted to a pointer to its first element first.
In C23, what does the declaration int f(); mean?
C23 removed old-style (K&R) declarations, so empty parentheses now mean "no parameters", exactly like C++. Before C23 they meant "parameters not specified" and calls were not checked – which is why (void) is still the portable spelling.
What is the main purpose of a function prototype?
The prototype gives the return type and parameter types before the first call, so the compiler can reject wrong calls and convert arguments (for example an int passed to a double parameter).
Which is true about static int count = 0; declared inside a function?
A static local variable has static storage duration: it exists for the whole run, is initialised once (before the program starts), and keeps its value. Its scope is still only the function.
What does static do when written before a function definition at file level?
At file scope, static gives internal linkage: the name is invisible to other .c files. It prevents name clashes and lets the compiler optimise more. It does not affect the function's local variables.
In which order are the arguments of f(a(), b()) evaluated?
The C standard leaves the order unspecified. Code whose result depends on it, such as printf("%d %d", next(), next()), may print differently on different compilers. Call the functions in separate statements.
What happens with a definition like add(int a, int b) { return a + b; } in C99 and later?
C89 assumed int when the type was missing ("implicit int"). C99 removed this rule, and modern compilers reject it or at least warn loudly. Always write the return type.
Which statement about recursion in C is true?
Every call has its own parameters and locals in a new stack frame. Too many nested calls – for example a missing base case – exhaust the stack. The standard does not guarantee tail-call optimisation.
Which is true about returning an array from a function?
Array types are not allowed as return types. Wrap the array in a struct (returned by value), fill an array passed in by the caller, or return a pointer to heap or static memory – never to a local array.
What does inline mean for a C function?
inline suggests expanding calls in place and changes linkage rules, but the compiler decides. Unlike a macro, an inline function is type-checked and evaluates each argument exactly once.
Timed online tests with instant scores and explanations.