Previous | Home | Next |
Storage classes define the scope and lifetime of the variable and function within a C program.
Types of storage classes in C :
- Auto storage class : This is the default storage class for local variable.
{ int num; auto int month; }
- Register storage class : This is used to define the local variable that should be stored in register instead of RAM.
{ register int miles; }
- Static storage class : This is the default storage class for global variables.
{ int num; static int count; main() printf(“%d”,count); }
- Extern storage class : Extern is used to give a reference of a global variable that is visible to all the program files.
int count=5; main() { write_extern(); } //////////////////////// void write_extern(void); extern int count; void write_extern(void) { printf("count is %i\n", count); }
Here extern keyword is being used to declare count in another file.
Previous | Home | Next |