• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Storage classes in C

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

 

 

Summary
Review Date
Reviewed Item
Storage classes in C
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Storage classes in C"

Leave a Message

Your email address will not be published. Required fields are marked *

Site Disclaimer, Copyright © 2016 - All Rights Reserved.