Showing posts with label extern. Show all posts
Showing posts with label extern. Show all posts

Wednesday 14 March 2018

Storage Classes in Cprogramming

A storage class repsents  the scope  and life-time of variables which helps programmers to define a particular variable during program's runtime.
These storage classes are preceded by the data type  There are 4 types of  storage class.

  1. auto
  2. register
  3. static
  4. extern
1 Auto:-  By default it  is associated  with all local variables as its storage class
eg:-
int  number;
or
auto int number;

2. Register:- It  is used to define local variables which will  be stored in a register instead of RAM. This means that the variable has a maximum size which is equivalent to the register size .
 it is used  to make program execution faster.
eg:-
register int  counter;

3.Static::- The static storage class instructs the compiler to keep a local variable in existence during the life-time of the program. Static storage class has its scope local to the function in which it is define,
The keyword used to define this storage class is static.
eg:-
static int var = 9

4.Extern:- Variables that are declared outside of all functions are known as external variables. External or global variables are accessible to any function.

    It can be said that an extern variable is a global variable which is assigned with a value that can be accessed and used within the entire program.
eg:-
#include <stdio.h>

   int val;
  extern void funcGlobal();

main() 
{
   val = 15;
   funcGlobal();
}
For more info click here