Storage Classes in C++ — Volkswagen Pointer I

14 мая 2015 | Author: | Комментарии к записи Storage Classes in C++ — Volkswagen Pointer I отключены
Volkswagen Pointer I

Storage Classes in C++

static

mutable

The auto Storage

The auto storage class is the storage class for all local

The example above defines two with the same storage auto can only be used functions, i.e. local

The register Storage Class

The storage class is used to local variables that be stored in a register instead of This means that the has a maximum size equal to the size (usually one word) and have the unary » applied to it (as it does not have a location).

The register should only be for variables that require access such as counters. It also be noted that ‘register’ does not mean the variable will be stored in a It means that it MIGHT be in a register depending on hardware and restrictions.

The static Storage

The static storage class the compiler to keep a local in existence during the life-time of the instead of creating and destroying it time it comes into and out of scope. Therefore, making variables static allows to maintain their values function calls.

The static modifier may also be to global variables. When is done, it causes that scope to be restricted to the file in it is declared.

In C++, when is used on a class data it causes only one copy of member to be shared by all objects of its

When the above code is and executed, it produces the following

The extern Storage Class

Volkswagen Pointer I

The storage class is used to a reference of a global variable is visible to ALL the program files. you use ‘extern’ the variable cannot be as all it does is point the variable at a storage location that has previously defined.


When you have multiple and you define a global variable or which will be used in files also, then will be used in another to give reference of defined or function. Just for understanding is used to declare a global or function in another file.

The modifier is most commonly when there are two or more sharing the same global or functions as explained below.

File: main.cpp

Second support.cpp

Here, extern is being used to declare in another file. Now compile two files as follows:

This will produce executable program, try to execute and check the result as follows:

The Storage Class

The mutable applies only to class which are discussed later in tutorial. It allows a member of an to override constness. That is, a member can be modified by a const function.

Volkswagen Pointer I
Volkswagen Pointer I
Volkswagen Pointer I
Volkswagen Pointer I
Volkswagen Pointer I

Interesting Articles

Other articles of the category "Pointer":

Twitter-news
Our partners
Follow us
Contact us
Our contacts

dima911@gmail.com

Born in the USSR

About this site

For all questions about advertising, please contact listed on the site.


Volkswagen all cars catalog with specifications, pictures, ratings, reviews and discusssions about cars Volkswagen.