12.07.2015 Views

C 프로그래밍 기초 - 한국기술교육대학교

C 프로그래밍 기초 - 한국기술교육대학교

C 프로그래밍 기초 - 한국기술교육대학교

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

변수의 선언 – 계속변수는 선언된 이후에만 사용할 수 있다.선언된 줄 이후부터 사용할 수 있다.예3.17)옆코드지역변수: n1, n2, n3광역변수: g1지역변수는 그것이 선언된 함수 내에서만사용할 수 있다.광역변수는 그것이 선언된 이후에 정의된모든 함수에서 사용할 수 있다.변수가 사용될 수 있는 범위를가시영역(scope)이라 한다.사용할 수 있는 범위가 같은 영역에같은 이름의 변수를 선언할 수 없다.void f1(void){int n1;} // f4()int g1;void f2(void){int n2;} // f2()void f3(void){int n3;} // f3()19/27변수의 사용예3.18)두 개의 정수를 입력 받아 합을 출력하는 프로그램/* sum.c */#include int main(void){int sum;int n1;int n2;printf("첫 번째 정수를 입력하시오: ");scanf("%d", &n1);printf("두 두 번째 정수를 입력하시오: ");scanf("%d", &n2);sum = n1+n2;printf("%d + %d = %d\n", n1, n2, sum);return 0;}20/27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!