Functions of C program (PART - 2)

Hello guys!!!! Welcome back! We studied functions part (1) in previews post. Now we will discuss some basic concept in the part (2).
So let’s start .
            First of all we will discuss about Local variables and Global variables.

LOCAL VARIABLES:
            Variables which are declared inside the body of the function. It cannot be accessed outside the function. These variables cannot initialize automatically.

GLOBAL VARIABLES:
            Variable is declared outside the body of the function. This variable can initialize automatically.

CALL BY VALUE:
            Argument value is passed to the function. Content of actual variable is copied into the formal variable. The called function cannot change the value of variable which are passed. When function tries to change the value of passed variable.

CALL BY REFERENCE:
            In call by reference, address is passed to the function not a value. It is used whenever we want to change the value of local variables declared in one function to be changed by other function.

RECURSION:
            The recursion is the process by which a function calls itself. Sometimes there must be some condition to stop recursion. Otherwise it will lead to infinite loop.Condition to stop recursion is called terminating condition. It has two parts. First is direct recursion. In this, function explicitly calls itself. Second is indirect recursion and in this, function calls another function.

Now we know that variables are stored in computer memory cells. This storage can be divided into different categories.
  • Register
  • Auto
  • Static
  • External
The storage class of variables decides where the variables will be stored. The syntax is:
            storage name datatype variable name;

AUTO:
            When we do not specify the storage specifier with variable that is auto. All the local variables have auto storage. These variables are stored in memory. When the function is called then auto variables are created. When function terminates, function is destroyed automatically.

REGISTER:
            Variables are to be stored in the register of CPU are called register variables. We can have limited numbers of register variables. This storage class should be used for variables which require fast access.

STATIC:
            The global variables are by default the static storage class. It’s default variable is 0. Static variable is available in the function in which it is defined.

EXTERNAL:
Normally we use this concept in all examples. Here is.

main()
{
.
.
.
}
Float b;
void fun1;
{
.
.
.
}

In this example, variable b is global variable because it is not available in main (). For access to main function, we have to use external storage class in declaration. So here is example.

main()
{
Extern float b;
.
.

}
Float b;
void fun1()
{
.
.
.
}

This example is for external. When a program is divided into more than onefile and we want one variable to be available in all the files of a program, we use variable with external storage class.
extern float b;
In one file, the variable named as b is already declared in some other files and there is no need to allocate memory to it.

So guys, this is functions part 2. My next post will be more exiting post. So keep watching my post.

To Like Our Facebook Page > NewAgeInformers 
 To follow us on  Twitter > Twitter
To Subscribe Our Youtube Channel > Wolfpack

Until then bye bye!!!


Comments