What is the extern storage class in C Programming

Follow by Email
Facebook0
Facebook
Google+
https://codingsec.net/2017/01/extern-storage-class-c-programming/

The extern storage class specifies that the variable is declared in some part of the program. Generally this storage class is used to refer global variables in a program. Note that extern variables cannot be initialized. The scope of a extern variable is throughout the entire program and the lifetime is until the program completes its execution.

In a multi-file program, a global variable in one file can be accessed from another file by using the storage class extern. Syntax for declaring a externvariable is as shown below:

static

The static storage class can be applied to both local variables and global variables. The static local variables are accessible only within the function or block in which they are declared, but their lifetime is throughout the program. The static global variables are accessible throughout the file in which they are declared but not in other files. Syntax for declaring static variable is shown below:

Example :

static int value;

register

When a variable is declared with the storage class register, the variable will be stored inside one of the registers of the CPU. The registers are under the direct control of CPU. So, data inside the register can be processed at a faster rate than the data that resides in the main memory. For a program to execute faster, it is always best to store the most frequently used data inside register. The scope and lifetime of a register variable is same as that of a auto variable. Syntax for declaring a register variable is as shown below:

Example :

register int value;

auto

When a variable is declared with the storage class auto, the variable’s scope is within the function or block in which it is declared and the lifetime is until the function or block in which it is declared completes. Syntax for declaring auto variable is shown below:

auto int value;

Take your time to comment on this article.

Follow by Email
Facebook0
Facebook
Google+
https://codingsec.net/2017/01/extern-storage-class-c-programming/

Add a Comment

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

Like the article? please consider sharing it. Thank you

Advertisment ad adsense adlogger