C 프로그래밍 언어에는 다음과 같은 네 가지 스토리지 클래스가 있습니다. -
- 자동
- 외부
- 정적
- 등록
전역 변수 / 외부 변수
키워드는 extern입니다. 이러한 변수는 블록 외부에서 선언됩니다.
-
범위 − 전역 변수의 범위는 프로그램 전체에서 사용할 수 있습니다.
-
기본값 0입니다.
알고리즘
알고리즘은 다음과 같습니다 -
START Step 1: Declare and initialized extern variable Step 2: Declare and initialized int variable a=3 Step 3: Print a Step 4: Call function step 5 Step 5: Called function Print a (takes the value of extern variable)
예시
다음은 extern storage class용 C 프로그램입니다. -
extern int a =5; /* this ‘a’ is available entire program */
main ( ){
int a = 3; /* this ‘a' is valid only in main */
printf ("%d",a);
fun ( );
}
fun ( ){
printf ("%d", a);
} 출력
출력은 다음과 같습니다 -
3 1
extern storage class에 대한 다른 프로그램 고려 -
예시
External.h
extern int a=14;
extern int b=8;
externstorage.c file
#include<stdio.h>
#include "External.h"
int main(){
int sub = a-b;
printf("%d -%d = %d ", a, b, sub);
return 0;
} 출력
출력은 다음과 같습니다 -
a-b=6