Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 4 C 프로그램 구성의 기본 C 프로그램에서 이름짓기 C 프로그램에서 이름 충돌/이름 재사용.

Similar presentations


Presentation on theme: "Lecture 4 C 프로그램 구성의 기본 C 프로그램에서 이름짓기 C 프로그램에서 이름 충돌/이름 재사용."— Presentation transcript:

1 Lecture 4 C 프로그램 구성의 기본 C 프로그램에서 이름짓기 C 프로그램에서 이름 충돌/이름 재사용

2 C 프로그램 must be a command. (why?) looks like: #include <stdio.h>
main() { int x=0; /* I like zero */ printf(“hello x is %d”, x); }

3 C 프로그램 구성 c program = declaration(s) + command declarations: 이름짓기
지은 이름들을 이용해서 명령문을 구성 이 명령문부분은 따로 main이라는 이름의 묶음안에 넣는다

4 이름짓기 Declarations (1/3) 변수 variables: 메모리에 이름짓기
사용할 메모리에 이름붙이기 그 메모리에 보관될 값들의 타입을 정하기 프로시져 procedure: 명령문에 이름짓기 명령문 묶음에 이름붙이기 프로시져의 인자값과 결과값의 타입을 정하기 타입 types: 타입 이름 짖기 복잡한 타입에 하나의 이름을 짖는다

5 이름 짓기 declarations (2/2) 프로시져 procedures 변수 variables int add(int x) {
char y; x = 0; y = ‘c’; 프로시져 procedures int add(int x) { return x+1; } int x = 0; x = add(10);

6 C 프로그램(decls + cmd) 예 #include <stdio.h> int s;
int add(int x) { return x+1;} void main() { int y = 10; s = 0; y = y + add(s); printf(“y+s+1 is %d”, y+add(s)); }

7 이름짖기 문제: 이름충돌 (1/3) #include <stdio.h> int s;
int add(int x) { return x+1;} void main() { int y = 10; s = 0; y = y + add(s); printf(“y+s+1 is %d”, y+add(s)); }

8 이름짖기 문제: 이름충돌 (2/3) #include <stdio.h> int s;
int add(int y) { return x+1;} void main() { int y = 10; s = 0; y = y + add(s); printf(“y+s+1 is %d”, y+add(s)); }

9 이름짖기 문제: 이름충돌 (3/3) #include <stdio.h> int s;
int add(int x) { return x+1;} void main() { int add = 10; s = 0; add = add + add(s); printf(“y+s+1 is %d”, y+add(s)); }

10 이름짖기 문제의 해결 (1/4) 이름의 유효범위(scope)가 정해져 있슴 유효범위을 제한하는 방법 유효범위(box) 만들기:
{ int x; … } f(int x) {…}

11 이름짖기 문제의 해결 (2/4) int x int y x x y int x int y x y x

12 이름짖기 문제: 이름충돌 (2/3) #include <stdio.h> int s;
int add(int y) { return x+1;} void main() { int y = 10; s = 0; y = y + add(s); printf(“y+s+1 is %d”, y+add(s)); }

13 이름짖기 문제: 이름충돌 (3/3) #include <stdio.h> int s;
int add(int x) { return x+1;} void main() { int add = 10; s = 0; add = add + add(s); printf(“y+s+1 is %d”, y+add(s)); }


Download ppt "Lecture 4 C 프로그램 구성의 기본 C 프로그램에서 이름짓기 C 프로그램에서 이름 충돌/이름 재사용."

Similar presentations


Ads by Google