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

Advantages of C++ Language
Advantages of C++ - C++ is a profoundly convenient dialect and is frequently the dialect of decision for multi-gadget, multi-stage application advancement. - C++ is a protest situated programming dialect...

How to Writing Cleaner & Better Code
For writing code, you need to learn How to writing cleaner & better code. Today I will give you some tips to write cleaner and better system. Below are some suggestions:1) Use Descriptive Names 2)...

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...

FUNDAMENTALS OF COMPUTER ALGORITHMS
INTRODUCTION: The word algorithm is named after the ninth century scholar 'Abu Jafar Muhammad Ibn Musa Al-Khwarizmi'. An algorithm is a step-by-step procedure by which a computer can produce the required...
M

Mukesh Tekwani

2 0
0

Coding for Children: Scratch
What is coding? Coding has become a must-have skill in this 21st century. Coding, or computer programming, is how we communicate with Devices. Code mentions the machine what moves to make, and composing...
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