A function is a set of statements that accept inputs, do a specific computation, and return output. The aim is to combine some regularly or repeatedly performed actions into a function so that we may call it instead of writing the same code for different inputs.
Functions in C are classified into two types:
A "built-in function" is another name for a library function. There is already a compiler package that includes these functions, each with a specific meaning. Built-in functions have the advantage of being directly useable without the need for definition, whereas user-written functions must be declared and defined before they can be used.
User-defined functions or "tailor-made functions" are functions created by the programmer. The programmer can upgrade and modify user-defined functions as needed. When we write a case-specific function that is not defined in a header file, we must declare and define it ourselves using the syntax.
Information can be used as a parameter in functions. It acts as a variable within the function. Specified within brackets, after the function name. It uses a comma to separate several parameters.
If the number and/or type of parameters provided to two functions differ, they can have identical names. Overloaded functions are those that share the same name but take different arguments.
A default argument is a value specified in a function declaration that the compiler will assign if the caller function does not give a value for the argument. If any value is entered, the default value is overwritten.
In C, calling a function consists of invoking its name followed by brackets holding any required parameters. This initiates the function's execution and transfers control to the function body. After completing its purpose, the function may return a value, if declared, that can be assigned or used in the calling context.
When calling by value, the original value is not changed. The function parameter stores the passed-in value in the stack memory address. Changing the value of a function parameter affects only the current function. This will not alter the value of variables within the caller method, such as main().
We modify the original value by passing a reference (address). The address of the value is passed in the function, so the actual and formal parameters share the same address space. As a result, any changes to the value within the function are reflected both inside and outside of it.