Week 1-1. 컴퓨터 구조 및 프로그래밍 언어 개론 [Download]

Download Report

Transcript Week 1-1. 컴퓨터 구조 및 프로그래밍 언어 개론 [Download]

C Programming 개요
2003. 3. 4.
컴퓨터의 기본 구조
읽기
쓰기
중앙 처리 장치
입력 장치
2016-08-05
기억 장치
출력 장치
2
2016-08-05
3
Algorithmic Thinking
Very laborious
But not very smart

Must be told in detail
what to do
– 컴퓨터가 이해할 수
있도록
– 모든 경우에 대해

2016-08-05
Algorithmic Thinking
– Algorithms ==
Recipes
4
컴퓨터에게 일을 시키기 위한 과정
문제정의와
분석
2016-08-05
알고리즘
고안
프로그램 작성
5
프로그래밍
프로그래밍
알고리즘
작성
2016-08-05
+
코딩
6
프로그래밍

알고리즘
– 문제 해결 방법에 대한 단계적 풀이 과정

프로그램
– 알고리즘을 컴퓨터가 이해할 수 있는
언어로 풀어 쓴 것
2016-08-05
7
Programming Languages
Algorithms:
Developed by people
High-level languages
Programming
Languages
Assembly languages
Machine languages
Computers: Execute algorithms
2016-08-05
8
Programming 학습법

Learn by doing
– Do exercises/practices.
– Lectures will give you basic tools only.

In the lectures, you will learn:
– Language syntax
– Algorithmic thinking

Read ABC & Try by yourself
2016-08-05
9
Programming 학습법

Many bugs in your programs
Programming maturity comes with
p.r.a.c.t.i.c.e!!
2016-08-05
10
C 언어

C 언어
– Born in the early 1970s with UNIX
– Widely used
– The basis for C++ and Java
2016-08-05
11
C 프로그래밍 과정의 도식
목적 파일
원시 파일
#include <stdio.h>
main()
{
printf(“Hello\n”);
}
010010010101100100
010010010101100100
컴파일
실행 파일
010010010101100100
다른 목적 파일들과
라이브러리
링커
010010010101100100
010010010101100100
010010010101100100
010010010101100100
010010010101100100
010010010101100100
010010010101100100
010010010101100100
010010010101100100
2016-08-05
12
C 프로그래밍 과정 1/3
1.
C 원시파일(source file)의 작성
–
에디터 프로그램 이용
• Vi, Microsoft Visual C++의 에디터, MSDOS의 EDIT, ...
2016-08-05
13
C 프로그래밍 과정 2/3
2. 컴파일(compile)
1.원시파일을 목적코드(object codes)로
바꾸는 과정
2.컴파일러 프로그램 이용
2016-08-05
14
C 프로그래밍 과정 3/3
3.
링킹(linking)
–
목적코드(object codes)를 실행 가능한
프로그램(executable)으로 만드는 과정
링커(linker) 프로그램 이용
–
4.
디버깅(debugging)
–
–
5.
프로그램의 잘못된 부분을 수정하는 과정
디버거(debugger) 프로그램 이용
실행
2016-08-05
15
C 원시파일(source file)의 구성
#include <stdio.h>
int main(void)
{
printf(“Hello world!\n”);
return 0;
}
hello.c
2016-08-05
-화면에 “Hello world!”라
고 표시하는 프로그램
-프로그램의 시작은 우선
#include<stdio.h>를 써 넣
는 것부터 한다.
-프로그램의 본체는 int
main(void){ } 안의 부분이
다.
-프로그램은 return 0;으로
끝낸다.
16
C Program is …

A sequence of FUNCTIONS
– main() function executed first

A FUNCTION consists of:
– Declarations
– Statements

A Declaration: variable names and their types
– int my_score;

A Statement: data processing or control
– my_age = 18;
– if (average == 100) { …};
– printf(…);
2016-08-05
17
C 원시파일의 작성

C 원시파일의 이름
– 파일이름.c(소문자 c)
– 예: hello.c

작성도구
– 에디터 프로그램
2016-08-05
18
C 원시파일의 컴파일

원시파일을 목적파일로 바꾸는 과정.
– hello.c 파일을 가지고 hello.o(또는 hello.obj)
파일을 만드는 과정

목적파일(object file)
– 컴퓨터가 직접 이해할 수 있는 표현으로 되어 있는
파일

컴파일이 실패하는 경우
– 원시파일이 잘못되어 있을 때...
• C 언어의 형식에 맞지 않는 표현이 들어 있을 때
2016-08-05
19
잘못된 원시파일
#include <stdio.h>
-returm 0;은 C 언어 문법에
맞지 않는다.
int main(void)
{
printf(“Hello world!\n”);
returm 0;
}
- 컴파일러는 이 원시파일을
컴파일하지 못하고 에러메시
지를 출력한다.
- 디버깅: 원시파일의 returm
0;을 return 0;으로 수정한다.
hello.c
2016-08-05
20
잘못된 원시파일의 컴파일
2016-08-05
21
링킹 및 파일의 실행

링킹
– 목적파일을 가지고 실행 가능한 프로그램을
만드는 과정
• hello.o(또는 hello.obj)를 가지고 a.out(또는
hello.exe)를 만드는 과정

파일의 실행
– 화면에서 a.out 또는 hello라고 친다.
• 화면에 Hello world!라고 표시된다.
2016-08-05
22
실제 프로그램의 작성과 수행

Borland C compiler 이용하는 경우
– 실제 사용방법: 홈페이지 참조
• Assignments section
2016-08-05
23