UrbanPro
true

Learn Programming Languages from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

STORAGE CLASSES

P . akkaiah
29/12/2019 0 0

A storage class defines the scope (visibility) and life-time of variables and/or

functions within a C Program. They precede the type that they modify. We have

four different storage classes in a C program:

  • auto
  • register
  • static
  • extern

 

The auto Storage Class

The auto storage class is the default storage class for all local variables.

{

int mount;

auto int month;

}

The example above defines two variables within the same storage class. ‘auto’

can only be used within functions, i.e., local variables.

The register Storage Class

The register storage class is used to define local variables that should be stored

in a register instead of RAM. This means that the variable has a maximum size

equal to the register size (usually one word) and can't have the unary '&'

operator applied to it (as it does not have a memory location).

{

 

register int miles;

 

}

The register should only be used for variables that require quick access such as

counters. It should also be noted that defining 'register' does not mean that the

variable will be stored in a register. It means that it MIGHT be stored in a

register depending on hardware and implementation restrictions

The static Storage Class

The static storage class instructs the compiler to keep a local variable in

existence during the life-time of the program instead of creating and destroying

it each time it comes into and goes out of scope. Therefore, making local

variables static allows them to maintain their values between function calls.

The static modifier may also be applied to global variables. When this is done, it

causes that variable's scope to be restricted to the file in which it is declared.

In C programming, when static is used on a class data member, it causes only

one copy of that member to be shared by all the objects of its class.

The extern Storage Class

The extern storage class is used to give a reference of a global variable that is

visible to ALL the program files. When you use 'extern', the variable cannot be

initialized, however, it points the variable name at a storage location that has

been previously defined.

When you have multiple files and you define a global variable or function, which

will also be used in other files, then extern will be used in another file to provide

the reference of defined variable or function. Just for understanding, extern is

used to declare a global variable or function in another file.

The extern modifier is most commonly used when there are two or more files

sharing the same global variables or functions as explained below.

First File:

#include <stdio.h>

int count;

extern void write_extern();

main()

{

count = 5;

write_extern();

}

Second File:

#include <stdio.h>

extern int count;

void write_extern(void)

{

printf("count is %d\n", count);

 

}

0 Dislike
Follow 3

Please Enter a comment

Submit

Other Lessons for You

Address Calculation in Two Dimensional Arrays
Addresses of Two Dimensional arrays can be calculated by using 1. Row Major representation 2. Column major Representation 1. Row Major representaion: Let X be an array of M Rows and N Columns Address...

Programming Funds: Data == Information
Commonly, I used to ask this question in my classroom. Most of them will give the answers like: Data means information (or) Information means Data Which is correct? Are both same? Maybe...but not true. Here...

5 Key Benefits of Internship
As many of my connects are about to complete their graduation and post graduation, its been my good advice to them to find internship. Let me throw some light in this article on that area. An internship...
S

Shekhar Pawar

0 0
0

The ABCs Of Success For A Software Developer
“There is more to know for career advancement rather than focusing on codes and its challenges to become a successful developer”. A developer is the one who creates software application by...

Decorator Advanced ( Passing Parameter )
Hope you read our previous note about the basic concept of python-decorators, if not, please read first Let see what are the possible ways to utilise the decorators in real time.Well, here we are going...

Looking for Programming Languages Classes?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Programming Languages Classes?

The best tutors for Programming Languages Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Programming Languages with the Best Tutors

The best Tutors for Programming Languages Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more