What is the function call in C?
Before jumping to the function call, we need to understand the function in the C programming language. A function is a group of tasks used to execute the predefined operations and returns a value. A large program can be divided into small blocks of code that help to understand the logic, debug, and modified it.
In the C programming language, the function is divided into two parts: the built-in/ library function and the user-defined function.
Library/ Built-in Function
A library function is predefined functions, and its tasks are also defined in the C header files. So, it does not require writing the code of the particular function; instead, it can be called directly in a program whenever it is required. Example: printf(), scanf(), getch(), etc., are the predefined function in the C library, and the meaning of these functions cannot be changed.
Let's write a program to define the library function in C.
Welcome to the JavaTpoint.com It is the library function or built-in function in C
It is a user-defined function in the C programming language to execute some specific actions according to the programmer's requirement. A user-defined function is divided into three types such as function declaration, function definition, and function call.
A function declaration defines the name and return type of a function in a program. Before using the function, we need to declare it outside of a main() function in a program.
Example of function declaration:
In the above example, int is a return data type of the function name add function that contains two integer parameters as num1 and num2. Furthermore, we can write the above function declaration is as follows:
It defines the actual body of a function inside a program for executing their tasks in C.
In the above syntax, a function definition contains the three parts as follow:
Consider an example to demonstrate the function definition:
A function call is an important part of the C programming language. It is called inside a program whenever it is required to call a function. It is only called by its name in the main() function of a program. We can pass the parameters to a function calling in the main() function.
Let's consider a program to call a function in C programming languages.
Enter the first and second number 5 6 The sum of the two number is 11
Call by Value:
When single or multiple values of an actual argument are copied into the formal parameter of a function, the method is called the Call by Value. Hence, it does not alter the function's actual parameter using the formal parameter.
Consider a program to demonstrate the Call by Value in C programming.
x = 10, y = 20 from main before calling the function x = 15, y = 25 from modular function x = 10, y = 20 from main after calling the function
Call by Reference:
In this method, the address of the actual argument is copied into the function call's formal parameter; the method is known as Call by Reference. If we make some changes in the formal parameters, it shows the effect in the value of the actual parameter.
Consider a program to demonstrate the Call by Reference in C programming.
x = 10, y = 20 from main before calling the function x = 15, y = 25 from modular function x = 15, y = 25 from main after calling the function