External storage classes:
- Keyword: extern
- Memory: Inside RAM
- 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; } |