C Functions
Categories: C language
In c, we can divide a large program into the basic building blocks known as function. The function contains the set of programming statements enclosed by {}. A function can be called multiple times to provide reusability and modularity to the C program. In other words, we can say that the collection of functions creates a program. The function is also known as procedureor subroutinein other programming languages.
Advantage of functions in C There are the following advantages of C functions. 1. By using functions, we can avoid rewriting same logic/code again and again in a program. 2. We can call C functions any number of times in a program and from any place in a program. 3. We can track a large C program easily when it is divided into multiple functions. 4. Reusability is the main achievement of C functions. 5. However, Function calling is always a overhead in a C program. Function Aspects There are three aspects of a C function. 1. Function declaration A function must be declared globally in a c program to tell the compiler about the function name, function parameters, and return type. 2. Function call Function can be called from anywhere in the program. The parameter list must not differ in function calling and function declaration. We must pass the same number of functions as it is declared in the function declaration. 3. Function definition It contains the actual statements which are to be executed. It is the most important aspect to which the control comes when the function is called. Here, we must notice that only one value can be returned from the function. SNC function aspectsSyntax 1Function declarationreturn_type function_name (argument list); 2Function callfunction_name (argument_list) 3Function definitionreturn_type function_name (argument list) {function body;}