Entrance Exams
Govt. Exams
A recursive function is one that calls itself. It must have a base case to avoid infinite recursion.
int calculate(int a, float b, char c);
All three parameters must be provided in correct order and compatible types.
If a function with a non-void return type lacks a return statement, it returns undefined/garbage value. For void functions, no return is needed.
Declaration (prototype) tells the compiler about the function signature; definition provides the actual function body and implementation.
A function can be called as many times as needed within a program, limited only by memory and stack constraints.
int func(int x) { return x * 2; }
int main() { printf("%d", func(5)); }
func(5) returns 5 * 2 = 10, which is then printed.
Function declaration syntax is: return_type function_name(parameter_list);
In older C standards (before C99), if no return type is specified, the default is 'int'. However, this is deprecated in modern C standards.
In C, functions are defined by specifying the return type followed by the function name and parameters. No specific 'function' keyword is used.
Functions allow code reusability, modularity, and easier maintenance. They break down complex problems into smaller, manageable pieces.