ankitweblogic logo
W e b t u t o r i a l s

C Tutorial

Programing Approach


Flow Chart

Define C

Define Programming

C - Syntax

Compiler vs Interpreter

C - Variables

C - Keywords

C - Data Types

C - Comments

Turbo C - Shortcut keys

C - Operators

Hierarchy of Operators

Ex: Arithmetic Operator

C - Formatting Output

Constant Variable

C - Escape Sequence

C - if , switch

Ex: If condition

Ex: Inc / Dec Operator

C - loops

Ex: Loops

C - Nesting Of loops

Ex: Nested Loops

Jumping Statements

C - Arrays 1D

C - Arrays 2D

C - Sorting


Character I/O Function

C - String Functions

Ex: Strings

Array of Strings

C - Math Functions

User-defined Function

Exercise Function

C - Types of Functions

Storage Class

C - Header Files

C - Preprocessor

C - Pointers

C - Structures

C - Typedef

C - File Handling

Ex: File Handling

Command Line Argument


C - Storage classes

To define a variable we need to mention not only its data type but also its storage class. Storage classes will tell the compiler, where the variable is stored and what will be its default value. In C, different types of storage classes are:

  1. Local A variable that is declared inside the function or block is called local variable.
  2. void function()
        int x=10; //local variable  
  3. Automatic The auto storage class is the default storage class for all local variables. However you can use auto keyword to declare auto variable.
  4. void main()
        int x=10; //local variable (also automatic)  
        auto int y=20; //automatic variable  
  5. Register The register storage class is used to define local variables to be stored in a register instead of RAM.
  6. Static The static storage class instructs the compiler to keep a local variable in existence during the life-time of the program. Therefore, making local variables static allows to maintain their values between function calls.
  7. External It is also known as global variable and it is visible in ALL the functions. Global variable is declared outside the function or block. Value change in any function will reflect in other functions. Extern keyword is use to declare external variable.
  8. int value1=20;//global variable
    extern int value2=20;//global variable
    void function()
        printf("%d\n",value1); // 20
        printf("%d\n",value2); // 20
Difference Between Automatic, Register, Static and External classes.
S.No. Feature's Automatic Register Static External
1. Storage Ram CPU Ram Ram
2. Default value Garbage value Garbage value 0 0
3. Scope Local Local Local Global
4. Keyword auto register static extern
5. Speed Average Fast Average Average

Use register storage class very often because there are very few CPU registers and many of them might be busy.

Example 1: Local and Global variable.

int g = 10; //Global variable declaration and assignment
void show();
void main()
   int a=100; //Local variable declaration and assignment
   printf("Value inside main function is:\n");
   printf("A = %d\n",a);
   printf("G = %d\n",g);
void show()
   printf("Value outside main function is:\n");
   //printf("A = %d\n",a); //Error
   printf("G = %d\n",g);
Value inside main function is:
A = 100
G = 20

Value outside main function is:
G = 20

Example 2: Static variable.

    static int a=10;
    printf("%d ",a);
11 12 13 14 15 16 17 18 19 20
if we do not apply static keyword then the output will be:
11 11 11 11 11 11 11 11 11 11