CodersEditor Tutorials

CodersEditor Tutorials

  • Online IDE
  • Q&A
  • C Programming
  • Java
  • GraphQL.NET
  • System Software

›Introduction

C Programming

    Introduction

    • Overview
    • Installation & Setup
    • C Program Structure
    • Keywords & Identifiers
    • Data Types
    • Variables & Constants
    • Scope Rules
    • Storage Class
    • Standard Input and Output
    • Operators

    Control Flow/Decision Making

    • Overview
    • if Statement
    • if else Statement
    • Nested If statement
    • Switch Statement
    • Nested Switch Statement
    • Conditional Operators

    Loop

    • Loops Overview
    • While loop
    • For Loop
    • Do while
    • Nested Loops
    • Break
    • Continue Statement
    • Goto statement

    Arrays

    • Arrays
    • Multi Dimensional Arrays
    • Arrays & Functions

    Pointers

    • Pointers Basics
    • Pointers and Arrays
    • Pointers and Functions
    • Memory allocation

    Strings

    • String Basics
    • String Functions

    C Programming Examples

    • Basic Example 1

Storage Class in C Programming

This article is about what is a storage class and the different storage classes in c.

Storage Class in C programming

The storage class defines the location, visibility and lifetime of variables and functions inside a C program. It gives information about the variable. There are four different storage classes in the C program. They are as follows:

  • Auto
  • Static
  • Register
  • Extern

Auto Storage Class

This is the default storage class in C and the variables defined in this class are called local variables. The scope of a variable in this class is limited within a particular block only. The auto variables cannot be accessed outside the specific block. It contains a garbage value.

Example auto int age=21;

Static Storage Class

In static storage class, the variables can be defined in two ways.

  • Static local variable is a variable that retains its value between block or function calls and remains visible only to the block or function in which it is defined.
  • Static global variables are variables visible only to the file where it is declared.
  • The static variables by default hold the value zero.

Example static int year = 1999;

Register storage class

The variables declared in the register storage class are limited only to a particular block just like the auto storage class but the register storage class stores local variables within blocks or functions in CPU registers instead of RAM. This would help in quick access to the variables stored. Variables defined using the register storage class has a lifetime throughout the program. These variables have no default value and are often declared at the top of the program.

Example register int age;

Extern storage class

Global variables are declared using an extern storage class where the variables are shared between two or more files. Extern denotes external storage class.

Example extern i;

← Scope RulesStandard Input and Output →
  • Storage Class in C programming
    • Auto Storage Class
    • Static Storage Class
    • Register storage class
    • Extern storage class
CodersEditor Tutorials
CoderdEditor Developer Tools
CodersEditor Online EditorGit Flavoured Markup EditorFree Online JSON FormatterFind My IP Address Details
Tutorials
C ProgrammingJava
Copyright © 2021 CodersEditor.com