Storage Class in C Progrmming

1,058 views

Published on

This slide contain description about all the storage class available in C Programming language.

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,058
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
100
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Storage Class in C Progrmming

  1. 1. INTRODUCTION TYPES Storage Class in C
  2. 2. Introduction Storage class explain the behavior of the variable in terms of scope and lifetime, it also determine the initial of the variable. Scope of the variable is the region over which the variable is visible or valid. Life time of the variable is the time during which memory is associated with the variable. Initial value is the value assigned to the variable implicitly if no value is assigned to it by the programmer.
  3. 3. There are four types of storage class available in C:  Auto  Extern  Static  Register
  4. 4. Auto All local variables has this storage class. Default value is the garbage value. Scope of the variable is only between the blocks where it is declared. Lifetime is till the control remains within the block or function where these variables are defined. These variables are destroyed whenever block ends or function jump occur. To declare auto storage class auto keyword is used.
  5. 5. Example:  auto int n; Auto keyword is optional all the local variables by default fall under this storage class. Example:  int n;
  6. 6. Extern Scope is through out the program. Lifetime is till the end of the program. Initial value is 0. Extern keyword is used to declare the variable of this storage class.  extern int x; By default global variable has this storage class.
  7. 7. Static It is special case of local variable. These are defined inside the function or block. Its scope is inside the block or the function where it is defined. Initial value is 0. Its value is retained between different function calls. Lifetime is same as the global variable i.e. through out the program. Keyword static is used to define this type of variable.
  8. 8. Register Register variable behave in every way same as the auto variable. The only difference is that register variable are store inside the computer register instead of the memory. They are used when CPU has to access the variable very frequently. Eg looping variable They are defined by placing keyword register before the datatype of variable. Example  register int a=10;

×