Function Basics
Function Basics
Functions:
- Functions are used to divide a large C program into smaller and less complex pieces.
- Functions can be called multiple times to provide reusability and modularity to the C program.
- Functions are also called procedures, subroutines, or methods.
- A function is a piece of code that performs a specific task.
A function is nothing but a group of code put together and given a name. It can be called anytime without writing the whole code again and again in a program.
I know its syntax is a bit difficult to understand, but don’t worry. After reading this whole information about Functions, you will know each and every term or thing related to Functions.
Advantages of Functions:
- The use of functions allows us to avoid re-writing the same logic or code over and over again.
- With the help of functions, we can divide the work among programmers.
- We can easily debug or find bugs in any program using functions.
- Functions make code readable and less complex.
Aspects of a function:
- Declaration: This is where a function is declared to tell the compiler about its existence.
- Definition: A function is defined to get some task executed. (It means when we define a function, we write the whole code of that function, and this is where the actual implementation of the function is done.)
- Call: This is where a function is called to be used.
Types of functions:
- Library functions: Library functions are pre-defined functions in C Language. These are functions that are included in C header files prior to any other part of the code in order to be used. E.g., printf(), scanf(), etc.
- User-defined functions: User-defined functions are functions created by the programmer for the reduction of the complexity of a program. These are functions that the user creates as per the requirements of a program. E.g., Any function created by the programmer.