본문 바로가기
C/c언어 수업

p336 전역/지역변수 global/local variable

by sj0020 2020. 8. 6.
#include <stdio.h>
int fct1(void);
int fct2(void);
int fct3(void);

int val; //전역변수 val

int main(void)
{
	printf("%d \n", val); // print 0
	fct1();
	fct2();
	fct3();
	return 0;
}

int fct1(void)
{
	val++;
	printf("%d \n", val); // print 1
}

int fct2(void)
{
	val++;
	printf("%d \n", val); // print 2
}

int fct3(void)
{
	int val = 0; //전역변수를 가리는 지역변수
	val++;
	printf("%d \n", val);
}


'C > c언어 수업' 카테고리의 다른 글

p341지역변수 static - static variable 정적변수  (0) 2020.08.06
p345 register 레지스터  (0) 2020.08.06
p311 ascii  (0) 2020.08.06
p283 for, while  (0) 2020.08.05
p280 나이입력 do while , switch  (0) 2020.08.05