The scope and lifetime depends on the storage class of the variable in c language the variables, explain in detail with example program about External variables.

External Variables
       The variables which are declared outside the functions are called external variables. Since these variables are not declared within aa specific function, these are common to all the functions in the progrma. These variables should be referred by the same name and data type throughout the program. These varibales are alive and active throughout the program.
Definition:
      An external variable is defined in the same manner as the ordinary variable. This must appear outside the function. Variable definition will automatically allocate memory space. The assignment of initial values can be included within the definition.
Syntax:
extern [data_type] [variable_name];
Example:
extern int a;
Example Program:
/*  Program to demonstrate external storage class.
#include <stdio h>
#include <conio h>
extern int i=10;
void main()
{
       int i=20;
       void show(void);
       clrscr();
       printf("\n\t %d",i);
       show();
       getch();
}
void show(void)
{
       printf("\n\n\t %d",i);
}

0 Comment "The scope and lifetime depends on the storage class of the variable in c language the variables, explain in detail with example program about External variables."

Post a Comment