Storage classes in C

Ratings:
(4)
Views:478
Banner-Img
  • Share this blog:

Brief description about Storage classes in C

According to the storage classes of “c” the lifetime of the auto variable is restricted within the body that’s why how many times we are calling the abc function that many times it will created. 37 void xyz() { int a=5; --a; printf(“\na=%d”,a); } void main() { auto int a=10; ++a; xyz(); ++a; printf(“\na=%d”,a); } o/p : a=4; a=12;   void abc() { int a =10; --a; printf(“\na=%d”,a); }  

void main()

{ abc(); abc(); printf(“\n a=%d”,a); o/p : Error undefined symbol ‘a’  

  • According to the storage classes of ‘c’ by default any type of variable storage class specifier is auto.
  • The scope of the auto variable is restricted within the body that’s why abc() function related data, we can’t access in main() function

 

void main()

{ int a=10; clrscr(); auto int b=20; ++a; ++b; printf(“\n a=%d  b=%d”,a,b); }   o/p: Error declaration is not allowed here In ‘c’ programming language variable declaration must be exists top of the program before writing the first statement only.  

void main()

{ auto int a=5; int a=10; ++a; printf(“a=%d”,a); } o/p : Error multiple declaration for ‘a’   In any scope we construct a single variable by using anymore of unique name, if we are constructing multiple variable with the same name then it gives an error i.e, multiple declaration      

void main()

{ int a=5; ++a; printf(“\na=%d”,a); { auto int a=10; --a; printf(“\na=%d”,a); } o/p : a=6 a=9 a=7    

You liked the article?

Like : 0

Vote for difficulty

Current difficulty (Avg): Medium

Recommended Courses

1/15

About Author
Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.


Stay Updated


Get stories of change makers and innovators from the startup ecosystem in your inbox