- Functions help in modularizing a program into smaller simple parts.
- Functions are classified based upon: (a) who develops the function and (b) the parameter and the return type of the function.
- Based upon who developed the function, they are categorized as: (a) user-defined functions and (b) library functions.
- Based upon the parameter and the return type of the function, they are categorized as: (a) functions with no input and no output, (b) functions with inputs but no output, (c) functions with inputs and a single output and (d) functions with inputs and multiple outputs.
- User-defined functions are defined by the user at the time of writing a program and are also known as programmer-defined functions.
- There are three aspects of working with user-defined functions: (a) function declaration, (b) function definition and (c) function call.
- Function definition, also known as function implementation means composing a function. Every function definition consists of two parts: (a) header of the function and (b) body of the function.
- A function with no input–output does not accept any input and does not return any result.
- The execution of a C program always begins with the function main. It need not to be called explicitly.
- Functions whose return type is void are known as void functions. void functions do not return any value.
- While calling a function, the expressions that appear within the parentheses of a function call are known as actual arguments, and the variables declared in the parameter list in the header of function definition are known as formal parameters.
- The return statement is to return the result of computations done in the called function and/or the program control back to the calling function.
- There are two forms of return statement: (a) return; and (b) return expression;.
- Depending upon whether values or addresses are passed as arguments to a function, the argument passing methods in C language are classified as: (a) pass by value and (b) pass by reference/address.
- If arguments are passed by value, the changes made in the values of formal parameters inside the called function are not reflected back to the calling function.
- If the arguments are passed by reference/address, the changes made in the values pointed to by the formal parameters in the called function are reflected back to the calling function.
- A function can return only one value by using the return statement but it can indirectly return more than one value using the concept of pass by reference/address.
- When an array is passed as an argument to a function, it implicitly gets converted to a pointer type.
- The arguments can be made default by using an initialization syntax within the parameter list during the function declaration.
- The default argument should not be specified in the function definition.
- Function calling itself is called recursive function and the process is known as recursion.
- Recursive functions may be: (a) direct recursive/indirect recursive and (b) tail recursive/non-tail recursive.
- There are three patterns of recursive calls: (a) linear, (b) binary and (c) n-ary.
- Like recursion, pointers to functions provide an extremely interesting, efficient and elegant programming technique.
- A pointer to a function, commonly known as the function pointer, is a variable that points to the address of a function.
- Library functions or pre-defined functions are the functions whose functionality has already been developed by someone and is available to the user for use.
- The arguments to the function main are supplied at the command line and thus have a special name known as command line arguments.