A function is a block of code that performs a specific task. C allows you to define functions according to your need. These functions are known as user-defined functions.
There can be 4 different types of user-defined functions, they are:
1.Function with no arguments and no return value
2.Function with no arguments and a return value
3.Function with arguments and no return value
4.Function with arguments and a return value
Function prototype
A function prototype is simply the declaration of a function that specifies function's name, parameters and return type. It doesn't contain function body.
A function prototype gives information to the compiler that the function may later be used in the program.
Syntax of function prototype
returnType functionName(type1 argument1, type2 argument2, ...);
Calling a function
Control of the program is transferred to the user-defined function by calling it.
Syntax of function call
functionName(argument1, argument2, ...);
Return Statement
The return statement terminates the execution of a function and returns a value to the calling function. The program control is transferred to the calling function after the return statement.
Syntax of return statement
return (expression);
The type of value returned from the function and the return type specified in the function prototype and function definition must match.
Top comments (0)