- When we opened a file we must close such file, otherwise data will damage.
- “fclose” function is used to close a file.
- Example fclose(fp);
IMPORTANCE OF FUNCTIONS:
- A function is a piece of code written to perform a specific task.
- Importance and Advantages are
- A large program can be divided into small units or modules. These are written as Functions.
- Each function is written to perform specific task. This makes writing and testing of program easier.
- Many programmers can work on one program at a time. So program develop quickly.
- A function can be use in other program.
- Use of functions also reduces overall length of the program.
TYPES OF FUNCTIONS:
- Built-In Functions (These functions are defined already in the language. We can’t use these functions in any other program. Also called Library Functions. (i.e.) printf ( ), sqrt ( ) etc.).
- User-Defined Functions (User creates these functions. Also called Programmer-Defined functions. These functions are written for a specific use).
TYPES OF VARIABLES:
- Variables that are declared inside the main function or inside any user-defined function are called Local variables or automatic variables
- The keyword “auto” (optional) can be used to declare these variables.
auto int a, b, c; or
int a, b, c;
Life-Time of Local Variables:
- Life time is the time period between the creation and destruction of the variable.
- When control goes to that function in which variable is declared, then variable will created and occupy memory space and when control goes back to calling function then variable will be destroyed.
- A variable declared inside the function can not used in other function.