Skip to main content

Posts

Showing posts with the label local variables

What is Storage class and What are their types in C

 Variable declaration is not complete until we mention its storage class( there are some default conditions as well). Yeah you got it right ,Variables not only have data types they have storage class too. Why storage class? They tell us about The scope of the variable. Life time of the variable. Initial value of the the variable, if left unassigned. We have four storage class in C Automatic storage class External storage class Static storage class Register storage class Let us look at them one by one. Automatic Storage Class Scope : Local to the block where it is defined. Life Time : Until the control remains in the block. Initial value : A garbage value, one cannot predict. We use the keyword auto to declare a variable of automatic storage class. Demonstration of  Automatic storage class # include < stdio.h > void   myFunc (); int   main () {     auto  int   x   =   5 ;      printf ( " %d " , x ) ;      myFunc () ;      return   0 ; } void   myFunc () { int x;