C – External Storage Classes

External storage classes:

  1. Keyword: extern
  2. Memory: Inside RAM
  3. Scope: Can access anywhere in the application

Note: External variables always global variables. These variables get memory only when we initialize with any value.

External variables cannot be global:

#include<stdio.h>
int main()
{
            extern int a=10;
            printf(“a value is : %d \n”, a);
            return 0;
}

Global variables must be initialized with value. Runtime error raises if we access external variable without value.

#include<stdio.h>
extern int a;
int main()
{
            printf(“a value is : %d \n”, a);
            return 0;
}

Memory allocates only when we initialize:

#include<stdio.h>
extern int a=10;
int main()
{
            printf(“a value is : %d \n”, a);
            return 0;
}

The declaration statement will not consider, memory allocates only when we assign value:

#include<stdio.h>
extern int a;
extern int a;
extern int a;
extern int a=10;
int main()
{
            printf(“a value is : %d \n”, a);
            return 0;
}
Scroll to Top