Microsoft PowerPoint - ch07 - 포인터 pm0415

Size: px
Start display at page:

Download "Microsoft PowerPoint - ch07 - 포인터 pm0415"

Transcription

1 함수의인수 (argument) 전달방법 C 에서함수의인수전달방법 값에의한호출 (call-by-value): 기본적인방법 포인터에의한호출 (call-by-pointer): 포인터이용 참조에의한호출 (call-by-reference): 참조 (reference) 이용 7-35

2 값에의한호출 (call-by-value) 함수호출시에변수의값을함수에복사본으로전달 복사본이전달되며, 호출하는 (calling) 함수의변수와호출된 (called) 함수의인수 (argument) 는별도의변수로관리됨 호출된함수의인수가변경되어도, 호출한함수의변수는변경없음 값에의한호출은값만을복사해요. 100 int main(void) int i = 100; 100 i int sub( int v ) 100 v... sub( i );

3 Argument passing in Call-by-Value double average(int i, int j); void main(int argc, char *argv[]) int x, y; double d; x = 3; y = 5; d = average(x, y); printf( Average: %f n, d ); double average(int i, int j) double avg; Function Call: Function average() Return Function Call: main() stack frame for average( ) - arguments: int i, int j - local variables: double avg copy copy stack frame for main( ) - arguments: int argc, char * argv[] - local variables: int x, int y, double d Memory Stack return copy avg = (i + j)/2.0; return avg; 7-37

4 포인터에의한호출 (call-by-pointer) 함수호출시에변수의주소정보 ( 포인터 ) 를함수의매개변수로전달 참조에의한호출은주소를복사합니다. 96 int main(void) int i = 100;... sub( &i ); int sub( int *p ) i p 7-38

5 Argument passing in Call-by-Pointer double average(int *pi, int *pj); void main(int argc, char *argv[]) int x, y; double d; x = 3; y = 5; d = average(&x, &y); printf( Average: %f n, d ); double average(int *pi, int *pj) double avg; Function Call: Function average() Return Function Call: main() stack frame for average( ) - arguments: int *pi, int *pj - local copy variables: of double avg return addr copy copy of stack frame for main( ) addr - arguments: int argc, char * argv[] - local variables: int x, int y, double d Memory Stack avg = (*pi + *pj)/2.0; return avg; 7-39

6 참조에의한호출 (call-by-reference) 함수호출시에변수의주소정보 ( 참조 ) 를함수의매개변수로전달 함수의호출시에 calling 함수에서의호출은 call-by-value에서와동일 호출된함수에서의 parameter에는 & 표시가데이터유형다음에표시됨 call-by-reference의경우, 호출된함수에서호출한함수의변수값을변경할수있음 예 double average(int i, int j); // call-by-value double average(int& i, int& j); // call-by-reference void main(int argc, char *argv[]) int x, y; double d;..... d = average(x, y);

7 Argument passing in Call-by-Reference void average(int i, int j, int& sum, double& avg); void main(int argc, char *argv[]) int x, y, sum; double avg; x = 3; y = 5; average(x, y, sum, avg); cout << Sum: << sum; cout <<, Average: << avg; void average(int i, int j, int& sum, double& avg) sum = i + j; avg = sum/2.0; Function Call: Function average() Return Function Call: main() 7-41 stack frame for average( ) - arguments: int i, j, int&sum, double& avg - local variables: copy ref ref stack frame for main( ) - arguments: int argc, char * argv[] - local variables: int x, y, sum, double avg Memory Stack

8 swap() 함수 #1 call-by-value 변수 2 개의값을바꾸는작업을함수로작성 #include <stdio.h> void swap(int x, int y); int main(void) int a = 100, b = 200; printf("a=%d b=%d\n",a, b); swap(a, b); printf("a=%d b=%d\n",a, b); return 0; 100 a <main> b 함수호출시에값만복사된다. x y <swap> 7-42 void swap(int x, int y) int tmp; printf("x=%d y=%d\n",x, y); tmp = x; x = y; y = tmp; printf("x=%d y=%d\n",x, y); a=100 b=200 x=100 y=200 x=200 y=100 a=100 b=200

9 swap() 함수 #2 - call-by-pointer 포인터를이용 #include <stdio.h> void swap(int x, int y); int main(void) int a = 100, b = 200; printf("a=%d b=%d\n",a, b); swap(&a, &b); printf("a=%d b=%d\n",a, b); return 0; 함수호출시에주소가복사된다. void swap(int *px, int *py) int tmp; printf("*px=%d *py=%d\n", *px, *py); tmp = *px; *px = *py; *py = tmp; printf("*px=%d *py=%d\n", *px, *py); &a a &b b <main> px py <swap> 7-43 a=100 b=200 *px=100 *py=200 *px=200 *py=100 a=200 b=100

10 swap() 함수 #3 - call-by-reference 포인터를이용 #include <stdio.h> void swap(int& x, int& y); int main(void) int a = 100, b = 200; printf("a=%d b=%d n",a, b); swap(a, b); printf("a=%d b=%d n",a, b); return 0; 함수호출시에주소정보가전달된다. void swap(int & x, int &y) int tmp; printf("x=%d y=%d n", x, y); tmp = x; x = y; y = tmp; printf("x=%d y=%d n", x, y); a b <main> x y <swap> 7-44 a=100 b=200 x=100 y=200 x=200 y=100 a=200 b=100

11 파라메터전달방식의비교 /* TestParameterPassing.c */ #include <stdio.h> void swap_call_by_value (int x, int y); void swap_call_by_pointer(int *px, int *py); void swap_call_by_reference(int &x, int &y); void main() int x, y; x = 10; y = 30; printf(" nbefore call-by-value: x = %d, y = %d n", x, y); swap_call_by_value(x, y); printf("after call-by-value: x = %d, y = %d n", x, y); x = 5; y = 7; printf(" nbefore call-by-pointer: x = %d, y = %d n", x, y); swap_call_by_pointer(&x, &y); printf("after call-by-pointer: x = %d, y = %d n", x, y); x = 25; y = 50; printf(" nbefore call-by-reference: x = %d, y = %d n", x, y); swap_call_by_reference(x, y); printf("after call-by-reference: x = %d, y = %d n", x, y); printf(" n"); void swap_call_by_value(int a, int b) int temp; temp = a; a = b; b = temp; void swap_call_by_pointer(int *pa, int *pb) int temp; temp = *pa; *pa = *pb; *pb = temp; void swap_call_by_reference(int &a, int &b) int temp; temp = a; a = b; b = temp; 7-45

12 scanf() 함수 변수에값을저장하기위하여변수의주소를받는다. 7-46

13 2 개이상의결과를반환 #include <stdio.h> // 기울기와 y절편을계산 int get_line_parameter(int x1, int y1, int x2, int y2, float *slope, float *yintercept) if( x1 == x2 ) 기울기와 Y절편을인수로전달 return -1; else *slope = (float)(y2 - y1)/(float)(x2 - x1); *yintercept = y1 - (*slope)*x1; return 0; int main(void) float s, y; if( get_line_parameter(3,3,6,6,&s,&y) == -1 ) printf(" 에러 n"); 기울기는 , y절편은 else printf(" 기울기는 %f, y절편은 %f n", s, y); return 0; 7-47

14 일반변수 vs 배열 배열이함수인수인경우 // 매개변수 x에기억장소가할당 void sub(int x)... // b[] 에기억장소가할당되지않는다. void sub(int b[], int n)... 배열의경우, 크기가큰경우에복사하려면많은시간소모 배열의경우, 배열의주소를전달 7-48

15 예제 #include <stdio.h> void sub(int b[], int n); int main(void) int a[3] = 1,2,3 ; a[0] a[1] a[2] printf("%d %d %d\n", a[0], a[1], a[2]); sub(a, 3); printf("%d %d %d\n", a[0], a[1], a[2]); return 0; void sub(int b[], int n) b[0] = 4; b[1] = 5; b[2] = 6;

16 포인터를반환할때주의점 함수가종료되더라도남아있는변수의주소를반환하여야한다. 지역변수의주소를반환하면, 함수가종료되면사라지기때문에오류 int *add(int x, int y) int result; result = x + y; return &result; 지역변수 result 는함수가종료되면소멸되므로그주소를반환하면안된다! 7-50

17 이중포인터 (double pointer) 이중포인터 (double pointer) : 포인터를가리키는포인터 int i = 10; int *p = &i; int **q = &p; // i 는 int 형변수 // p 는 i 를가리키는포인터 // q 는포인터 p 를가리키는이중포인터 7-51

18 이중포인터 이중포인터의해석 7-52

19 이중포인터 // 이중포인터프로그램 #include <stdio.h> *q int main(void) int i = 100; int *p = &i; int **q = &p; **q p 포인터 *p = 200; printf("i=%d *p=%d **q=%d n", i, *p, **q); i 변수 i q 이중포인터 **q = 300; printf("i=%d *p=%d **q=%d n", i, *p, **q); return 0; **q == *(*q) i=200 *p=200 **q=200 i=300 *p=300 result **q=

20 예제 #2 #include <stdio.h> void set_pointer(char **q); char *proverb="all that glisters is not gold."; "All that glisters is not gold." int main(void) char *p="zzz"; set_pointer(&p); printf("%s \n", p); return 0; p *q q void set_pointer(char **q) *q = proverb; All that glisters is not gold. result 7-54

21 포인터배열 (array of pointers) 포인터배열 (array of pointers): 포인터를모아서배열로만든것 7-55

22 정수형포인터배열 int a = 10, b = 20, c = 30, d = 40, e = 50; int *pa[5] = &a, &b, &c, &d, &e ; 7-56

23 2 차원배열에문자열을저장 char fruits[4 ][10] = "apple", "blueberry", "orange", melon" ; a p p l e \0 b l u e b e r r y \0 2 차원배열을사용하면낭비되는공간이생성되죠. o r a n g e \0 낭비되는공간! m e l o n \0 7-57

24 문자형포인터배열 char *fruits[ ] = "apple", "blueberry", "orange", melon" ; a p p l e \0 fruits[0] fruits[1] fruits[2] fruits[3] b l u e b e r r y \0 o r a n g e \0 m e l o n \0 7-58

25 예제 // 문자열배열 #include <stdio.h> 각각의문자열의길이가달라도메모리의낭비가발생하지않는다. int main(void) int i, n; char *fruits[ ] = "apple", "blueberry", "orange", "melon" ; fruits[0] fruits[1] fruits[2] fruits[3] a p p l e \0 b l u e b e o r a n g m e l o n \0 r e \0 r y \0 // 배열원소개수계산 n = sizeof(fruits)/sizeof(fruits[0]); for(i = 0; i < n; i++) printf("%s \n", fruits[i]); apple result blueberry orange melon return 0; 7-59

26 배열포인터 배열포인터 (a pointer to an array) 는배열을가리키는포인터 7-60

27 예제 #include <stdio.h> int main(void) int a[5] = 1, 2, 3, 4, 5 ; int (*pa)[5]; int i; pa = &a; for(i=0 ; i<5 ; i++) printf("%d n", (*pa)[i]); return 0; result 7-61

28 다차원배열과포인터 2차원배열 int m[3][3] 1행->2행->3행->... 순으로메모리에저장 ( 행우선방법 ) 하나의열 m m[0][0] m[0][0] m[0][1] m[0][1] 1 행 m[0] 하나의행 m[0][2] m[0][2] m[1][0] m[1][0] m[1] m[0][0] m[0][0] m[0][1] m[0][1] m[0][2] m[0][2] m[1][1] m[1][1] 2 행 열 (column) m[1][0] m[1][0] 행m[2][0] m[2][0] (row) m[1][1] m[1][1] m[2][1] m[2][1] m[1][2] m[1][2] m[2][2] m[2][2] m[1][2] m[1][2] m[2][0] m[2][0] m[2] m[2][1] m[2][1] 3 행 7-62 m[2][2] m[2][2]

29 배열이름 m은 &m[0][0] m[0] 는 1행의시작주소 m[1] 은 2행의시작주소... 2 차원배열과포인터 m m[0] m[0] m[0][0] m[0][0] m[0][1] m[0][1] m[0][2] m[0][2] m[1] m[1] m[1][0] m[1][0] m[1][1] m[1][1] m[1][2] m[1][2] m[2] m[2] m[2][0] m[2][0] m[2][1] m[2][1] m[2][2] m[2][2] 7-63

30 2 차원배열의해석 m 은세개의원소를가지는배열이다. int m[3][3]; 해석의방향 그원소들은다시세개의원소로되어있다. 7-64

31 multi_array.c // 다차원배열과포인터 #include <stdio.h> int main(void) int m[3][3] = 10, 20, 30, 40, 50, 60, 70, 80, 9 0 ; printf("m = %p\n", m); printf("m[0] = %p\n", m[0]); printf("m[1] = %p\n", m[1]); printf("m[2] = %p\n", m[2]); printf("&m[0][0] = %p\n", &m[0][0]); printf("&m[1][0] = %p\n", &m[1][0]); printf("&m[2][0] = %p\n", &m[2][0]); return 0; m m[0] m[1] m[2] m = m[0] = m[1] = m[2] = &m[0][0] = &m[1][0] = &m[2][0] = m[0][0] m[0][1] m[0][2] m[1][0] m[1][1] m[1][2] m[2][0] m[2][1] m[2][2] result 7-65

32 Multidimensional Dynamic Arrays 2-dimensional Dynamic Array of double type (1) double DA[ROWS][COLS]; ppda step-2: one-dimensional array of COLS double elements this element can be accessed as ppda[0][0] step-1: one-dimensional array of ROWS pointers to 4 rows (4 one-dimensional array) this element can be accessed as ppda[3][2] can be considered as four rows of one dimensional array: DA[i][0..4] each row is pointed by a pointer to 1-dimension array: Array of pointers to the four 1-dimension arrays of pointers double **ppda = (double **)malloc(sizeof(double *) * ROWS); To make the 2-dimensional array ppda[i] = (double *)malloc(sizeof(double) * COLS); 7-66

33 Multidimensional Dynamic Arrays Multi-dimensional array is "arrays of arrays" Type definitions help "see it": #define NUM_ROWS 3 #define NUM_COLS 4 int **ma; ma = (int **)malloc(sizeof(int *) * NUM_ROWS); // Creates array of three pointers // We can make each m[i] to point an dynamically allocated array of 4 integers for (int i = 0; i < NUM_ROWS; i++) ma[i] = (int *)malloc(sizeof(int) * NUM_COLS); // Results in 3 x 4 dynamic array! 7-67

34 2-dimensional Dynamic Array of double type (2) double **ppda = (double **)malloc (sizeof(double*) * NUM_ROW); for (int i=0; i<num_row; i++) ppda[i] = (double *) malloc (sizeof(double) * NUM_COLUMN); ppda[2][3] = 1.0; typedef double* DblPtr DblPtr *ppdb = (DblPtr *)malloc(sizeof(dblptr) * NUM_ROW); for (int i=0; i<num_row; i++) ppdb[i] = (DblPtr) malloc (sizeof (double) * NUM_COLUMN); ppdb[2][3] = 1.0; 7-68

35 2 차원배열과포인터연산 2 차원배열 m[][] 에서 m 에 1 을더하거나빼면어떤의미일까? 7-69

36 포인터를이용한배열원소방문 행의평균을구하는경우 double get_row_avg(int m[][cols], int r) int *p, *endp; double sum = 0.0; m[0][0] m[0][0] m[0][1] m[0][1 ] m[0][2] m[0][2] p = &m[r][0]; endp = &m[r][cols]; while( p < endp ) sum += *p++; 열 (column) m[1][0] m[1 ][0] 행m[2][0] m[2][0] (row) m[3][0] m[3][0] m[1][1] m[1 ][1 ] m[2][1] m[2][1 ] m[3][1] m[3][1 ] m[1][2] m[1][2] m[2][2] m[2][2] m[3][2] m[3][2] sum /= COLS; return sum; p endp endp 7-70

37 포인터를이용한배열원소방문 전체원소의평균을구하는경우 double get_total_avg(int m[][cols]) int *p, *endp; double sum = 0.0; m[0][0] m[0][0] m[0][1 m[0][1 ] ] m[0][2] m[0][2] p = &m[0][0]; endp = &m[rows-1][cols]; m[1][0] m[1][0] m[1][1 m[1 ][1 ] ] m[1][2] m[1][2] while( p < endp ) sum += *p++; sum /= ROWS * COLS; return sum; p m[2][0] m[2][0] m[3][0] m[3][0] m[2][1 m[2][1 ] ] m[3][1] m[3][1] 열 (column) 행(row) m[2][2] m[2][2] m[3][2] m[3][2] endp endp 7-71

38 const 포인터 const 를붙이는위치에따라서의미가달라진다. p 가가리키는내용이변경되지않음을나타낸다. 포인터 p 가변경되지않음을나타낸다. const char *p; char * const p; 7-72

39 예제 #include <stdio.h> int main(void) char s[] = "Barking dogs seldom bite."; char t[] = "A bad workman blames his tools"; const char * p=s; char * const q=s; //p[3] = 'a'; p 가가리키는곳의내용을변경할수없다. p = t; q[3] = 'a ; 하지만 p 는변경이가능하다. q 가가리키는곳의내용은변경할수있다. //q = t; 하지만 q 는변경이불가능하다. return 0; 7-73

40 main() 함수의인수 지금까지의 main() 함수형태 int main(void).. 외부로부터입력을받는 main() 함수형태 int main(int argc, char *argv[])

41 인수전달방법 C: \cprogram> mycopy src dst m y c c o o p y \0 \0 argv[0] s s r r c c \0 \0 argv[1] d s s t t \0 \0 3 3 argv[2] argc argv 배열 7-75

42 비주얼 C++ 프로그램인수입력방법 Project -> <YourProjectName> Properties -> Configuration Properties -> Debugging -> Command Arguments (Visual Studio 2015) 7-76

43 /* Power.cpp */ power.c #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) char mode; if (argc < 4) printf("usage: >power r (or i) base exponent"); exit(-1); printf("argc: %d n", argc); for (int i = 0; i < argc; i++) printf("argv[%d] : %s n", i, argv[i]); if (*argv[1] == 'r') printf("power(base, exponent) calculation with recursive mode n"); else if (*argv[1] == 'i') printf("power(base, exponent) calculation with recursive mode n"); 7-77

44 main 함수로 arguments 전달프로그램실행예제 (1) 7-78

45 main 함수로 arguments 전달프로그램실행예제 (2) 7-79

제 14 장포인터활용 유준범 (JUNBEOM YOO) Ver 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다.

제 14 장포인터활용 유준범 (JUNBEOM YOO) Ver 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 제 14 장포인터활용 유준범 (JUNBEOM YOO) Ver. 2.0 jbyoo@konkuk.ac.kr http://dslab.konkuk.ac.kr 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 이번장에서학습할내용 이중포인터란무엇인가? 포인터배열 함수포인터 다차원배열과포인터 void 포인터 포인터는다양한용도로유용하게활용될수있습니다. 2 이중포인터

More information

<4D F736F F F696E74202D20C1A63134C0E520C6F7C0CEC5CD5FC8B0BFEB>

<4D F736F F F696E74202D20C1A63134C0E520C6F7C0CEC5CD5FC8B0BFEB> 쉽게풀어쓴 C 언어 Express 제 14 장포인터활용 이중포인터 이중포인터 (double pointer) : 포인터를가리키는포인터 int i = 10; int *p = &i; int **q = &p; // i 는 int 형변수 // p 는 i 를가리키는포인터 // q 는포인터 p 를가리키는이중포인터 이중포인터 이중포인터의해석 이중포인터 // 이중포인터프로그램

More information

ch15

ch15 쉽게풀어쓴 C 언어 Express 제 14 장포인터활용 C Express 이중포인터 이중포인터 (double pointer) : 포인터를가리키는포인터 int i = 10; int *p = &i; int **q = &p; // i 는 int 형변수 // p 는 i 를가리키는포인터 // q 는포인터 p 를가리키는이중포인터 이중포인터 이중포인터의해석 이중포인터 //

More information

untitled

untitled int i = 10; char c = 69; float f = 12.3; int i = 10; char c = 69; float f = 12.3; printf("i : %u\n", &i); // i printf("c : %u\n", &c); // c printf("f : %u\n", &f); // f return 0; i : 1245024 c : 1245015

More information

11장 포인터

11장 포인터 누구나즐기는 C 언어콘서트 제 9 장포인터 이번장에서학습할내용 포인터이란? 변수의주소 포인터의선언 간접참조연산자 포인터연산 포인터와배열 포인터와함수 이번장에서는포인터의기초적인지식을학습한다. 포인터란? 포인터 (pointer): 주소를가지고있는변수 메모리의구조 변수는메모리에저장된다. 메모리는바이트단위로액세스된다. 첫번째바이트의주소는 0, 두번째바이트는 1, 변수와메모리

More information

Microsoft PowerPoint - 제11장 포인터

Microsoft PowerPoint - 제11장 포인터 쉽게풀어쓴 C 언어 Express 제 11 장포인터 이번장에서학습할내용 포인터이란? 변수의주소 포인터의선언 간접참조연산자 포인터연산 포인터와배열 포인터와함수 이번장에서는포인터의기초적인지식을학습한다. 포인터란? 포인터 (pointer): 주소를가지고있는변수 1003 1004 1005 영화관 1002 1006 1001 포인터 (pointer) 1007 메모리의구조

More information

Microsoft PowerPoint - 제11장 포인터(강의)

Microsoft PowerPoint - 제11장 포인터(강의) 쉽게풀어쓴 C 언어 Express 제 11 장포인터 이번장에서학습할내용 포인터이란? 변수의주소 포인터의선언 간접참조연산자 포인터연산 포인터와배열 포인터와함수 이번장에서는포인터의기초적인지식을학습한다. 포인터란? 포인터 (pointer): 주소를가지고있는변수 1003 1004 1005 영화관 1002 1006 1001 포인터 (pointer) 1007 메모리의구조

More information

Microsoft PowerPoint - chap-11.pptx

Microsoft PowerPoint - chap-11.pptx 쉽게풀어쓴 C 언어 Express 제 11 장포인터 컴퓨터프로그래밍기초 이번장에서학습할내용 포인터이란? 변수의주소 포인터의선언 간접참조연산자 포인터연산 포인터와배열 포인터와함수 이번장에서는포인터의기초적인지식을학습한다. 컴퓨터프로그래밍기초 2 포인터란? 포인터 (pointer): 주소를가지고있는변수 컴퓨터프로그래밍기초 3 메모리의구조 변수는메모리에저장된다. 메모리는바이트단위로액세스된다.

More information

제 11 장포인터 유준범 (JUNBEOM YOO) Ver 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다.

제 11 장포인터 유준범 (JUNBEOM YOO) Ver 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 제 11 장포인터 유준범 (JUNBEOM YOO) Ver. 2.0 jbyoo@konkuk.ac.kr http://dslab.konkuk.ac.kr 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 이번장에서학습할내용 포인터이란? 변수의주소 포인터의선언 간접참조연산자 포인터연산 포인터와배열 포인터와함수 이번장에서는포인터의기초적인지식을학습합니다.

More information

Microsoft PowerPoint - ch07 - 포인터 pm0415

Microsoft PowerPoint - ch07 - 포인터 pm0415 2015-1 프로그래밍언어 7. 포인터 (Pointer), 동적메모리할당 2015 년 4 월 4 일 교수김영탁 영남대학교공과대학정보통신공학과 (Tel : +82-53-810-2497; Fax : +82-53-810-4742 http://antl.yu.ac.kr/; E-mail : ytkim@yu.ac.kr) Outline 포인터 (pointer) 란? 간접참조연산자

More information

Microsoft PowerPoint - Chapter14_17.pptx

Microsoft PowerPoint - Chapter14_17.pptx Computer Engineering g Programming g 2 - 제 17 장동적메모리와연결리스트 - 제 14 장포인터활용 Lecturer: JUNBEOM YOO jbyoo@konkuk.ac.kr 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 이번장에서학습할내용 동적할당메모리 연결리스트 이중포인터 포인터배열 다차원배열과포인터 main

More information

Microsoft PowerPoint - Lesson14.pptx

Microsoft PowerPoint - Lesson14.pptx 2008 Spring Computer Engineering g Programming g 1 Lesson 14 - 제 17 장동적메모리와연결리스트 - 제14 장포인터활용 Lecturer: JUNBEOM YOO jbyoo@konkuk.ac.kr 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 이번장에서학습할내용 동적할당메모리 연결리스트 이중포인터

More information

Microsoft PowerPoint - Lesson14.pptx

Microsoft PowerPoint - Lesson14.pptx 2009 Spring Computer Engineering g Programming g 1 Lesson 14 - 제 17 장동적메모리와연결리스트 - 제14 장포인터활용 Lecturer: JUNBEOM YOO jbyoo@konkuk.ac.kr 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 이번장에서학습할내용 동적할당메모리 연결리스트 이중포인터

More information

금오공대 컴퓨터공학전공 강의자료

금오공대 컴퓨터공학전공 강의자료 C 프로그래밍프로젝트 Chap 14. 포인터와함수에대한이해 2013.10.09. 오병우 컴퓨터공학과 14-1 함수의인자로배열전달 기본적인인자의전달방식 값의복사에의한전달 val 10 a 10 11 Department of Computer Engineering 2 14-1 함수의인자로배열전달 배열의함수인자전달방식 배열이름 ( 배열주소, 포인터 ) 에의한전달 #include

More information

목차 포인터의개요 배열과포인터 포인터의구조 실무응용예제 C 2

목차 포인터의개요 배열과포인터 포인터의구조 실무응용예제 C 2 제 8 장. 포인터 목차 포인터의개요 배열과포인터 포인터의구조 실무응용예제 C 2 포인터의개요 포인터란? 주소를변수로다루기위한주소변수 메모리의기억공간을변수로써사용하는것 포인터변수란데이터변수가저장되는주소의값을 변수로취급하기위한변수 C 3 포인터의개요 포인터변수및초기화 * 변수데이터의데이터형과같은데이터형을포인터 변수의데이터형으로선언 일반변수와포인터변수를구별하기위해

More information

슬라이드 1

슬라이드 1 -Part3- 제 4 장동적메모리할당과가변인 자 학습목차 4.1 동적메모리할당 4.1 동적메모리할당 4.1 동적메모리할당 배울내용 1 프로세스의메모리공간 2 동적메모리할당의필요성 4.1 동적메모리할당 (1/6) 프로세스의메모리구조 코드영역 : 프로그램실행코드, 함수들이저장되는영역 스택영역 : 매개변수, 지역변수, 중괄호 ( 블록 ) 내부에정의된변수들이저장되는영역

More information

Data Structure

Data Structure Function & Pointer C- 언어의활용을위한주요기법 (3) Dong Kyue Kim Hanyang University dqkim@hanyang.ac.kr 함수의인자전달 함수의인자전달 함수의인자전달방식 인자전달의기본방식은복사다. 함수호출시전달되는값을매개변수를통해서전달받는데, 이때에값의복사가일어난다. int main(void) int val = 10;

More information

1 장 C 언어복습 표준입출력배열포인터배열과포인터함수 const와포인터구조체컴파일러사용방법 C++ 프로그래밍입문

1 장 C 언어복습 표준입출력배열포인터배열과포인터함수 const와포인터구조체컴파일러사용방법 C++ 프로그래밍입문 1 장 C 언어복습 표준입출력배열포인터배열과포인터함수 const와포인터구조체컴파일러사용방법 C++ 프로그래밍입문 1. 표준입출력 표준입출력 입력 : 키보드, scanf 함수 출력 : 모니터, printf 함수문제 : 정수값 2개를입력받고두값사이의값들을더하여출력하라. #include int main(void) int Num1, Num2; int

More information

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Function) 1. 함수의개념 입력에대해적절한출력을발생시켜주는것 내가 ( 프로그래머 ) 작성한명령문을연산, 처리, 실행해주는부분 ( 모듈 ) 자체적으로실행되지않으며,

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Chapter 10 포인터 01 포인터의기본 02 인자전달방법 03 포인터와배열 04 포인터와문자열 변수의주소를저장하는포인터에대해알아본다. 함수의인자를값과주소로전달하는방법을알아본다. 포인터와배열의관계를알아본다. 포인터와문자열의관계를알아본다. 1.1 포인터선언 포인터선언방법 자료형 * 변수명 ; int * ptr; * 연산자가하나이면 1 차원포인터 1 차원포인터는일반변수의주소를값으로가짐

More information

Microsoft PowerPoint - Chapter_08.pptx

Microsoft PowerPoint - Chapter_08.pptx 프로그래밍 1 1 Chapter 8. Pointers May, 2016 Dept. of software Dankook University http://embedded.dankook.ac.kr/~baeksj 포인터의개념 (1/6) 2 포인터란 : 다른객체를가리키는변수 객체의메모리주소를저장하는변수 기호적방식 (symbolic way) 으로주소사용 포인터와관련된연산자

More information

8장. 포인터

8장. 포인터 2019-1 st 프로그래밍입문 (1) 8 장포인터 박종혁교수 서울과학기술대학교컴퓨터공학과 UCS Lab Tel: 970-6702 Email: jhpark1@seoultechackr 목차 포인터의기본 포인터의개념 포인터의선언및초기화 포인터의사용 포인터의용도 포인터사용시주의사항 참조에의한호출 배열과포인터의관계 calloc() 과 malloc() 을이용한동적메모리할당

More information

설계란 무엇인가?

설계란 무엇인가? 금오공과대학교 C++ 프로그래밍 jhhwang@kumoh.ac.kr 컴퓨터공학과 황준하 6 강. 함수와배열, 포인터, 참조목차 함수와포인터 주소값의매개변수전달 주소의반환 함수와배열 배열의매개변수전달 함수와참조 참조에의한매개변수전달 참조의반환 프로그래밍연습 1 /15 6 강. 함수와배열, 포인터, 참조함수와포인터 C++ 매개변수전달방법 값에의한전달 : 변수값,

More information

<322EBCF8C8AF28BFACBDC0B9AEC1A6292E687770>

<322EBCF8C8AF28BFACBDC0B9AEC1A6292E687770> 연습문제해답 5 4 3 2 1 0 함수의반환값 =15 5 4 3 2 1 0 함수의반환값 =95 10 7 4 1-2 함수의반환값 =3 1 2 3 4 5 연습문제해답 1. C 언어에서의배열에대하여다음중맞는것은? (1) 3차원이상의배열은불가능하다. (2) 배열의이름은포인터와같은역할을한다. (3) 배열의인덱스는 1에서부터시작한다. (4) 선언한다음, 실행도중에배열의크기를변경하는것이가능하다.

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 System Software Experiment 1 Lecture 5 - Array Spring 2019 Hwansoo Han (hhan@skku.edu) Advanced Research on Compilers and Systems, ARCS LAB Sungkyunkwan University http://arcs.skku.edu/ 1 배열 (Array) 동일한타입의데이터가여러개저장되어있는저장장소

More information

Infinity(∞) Strategy

Infinity(∞) Strategy 배열 (Array) 대용량데이터 대용량데이터를다루는기법 배열 (Array) 포인터 (Pointer) 구조체 (Structure) 파일 (File) 변수 (Variable) 변수및메모리할당 변수선언 : int imsi; imsi 4 Bytes 변수선언 : char imsi2; imsi2 1 Byte 배열 (Array) 배열 동일한데이터형을가지고있는데이터들을처리할때사용

More information

쉽게 풀어쓴 C 프로그래밍

쉽게 풀어쓴 C 프로그래밍 제 3 장함수와문자열 1. 함수의기본적인개념을이해한다. 2. 인수와매개변수의개념을이해한다. 3. 함수의인수전달방법 2가지를이해한다 4. 중복함수를이해한다. 5. 디폴트매개변수를이해한다. 6. 문자열의구성을이해한다. 7. string 클래스의사용법을익힌다. 이번장에서만들어볼프로그램 함수란? 함수선언 함수호출 예제 #include using

More information

학습목차 2.1 다차원배열이란 차원배열의주소와값의참조

학습목차 2.1 다차원배열이란 차원배열의주소와값의참조 - Part2- 제 2 장다차원배열이란무엇인가 학습목차 2.1 다차원배열이란 2. 2 2 차원배열의주소와값의참조 2.1 다차원배열이란 2.1 다차원배열이란 (1/14) 다차원배열 : 2 차원이상의배열을의미 1 차원배열과다차원배열의비교 1 차원배열 int array [12] 행 2 차원배열 int array [4][3] 행 열 3 차원배열 int array [2][2][3]

More information

A Dynamic Grid Services Deployment Mechanism for On-Demand Resource Provisioning

A Dynamic Grid Services Deployment Mechanism for On-Demand Resource Provisioning C Programming Practice (II) Contents 배열 문자와문자열 구조체 포인터와메모리관리 구조체 2/17 배열 (Array) (1/2) 배열 동일한자료형을가지고있으며같은이름으로참조되는변수들의집합 배열의크기는반드시상수이어야한다. type var_name[size]; 예 ) int myarray[5] 배열의원소는원소의번호를 0 부터시작하는색인을사용

More information

Microsoft PowerPoint - chap10-함수의활용.pptx

Microsoft PowerPoint - chap10-함수의활용.pptx #include int main(void) { int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; } 1 학습목표 중 값에 의한 전달 방법과

More information

11장 포인터

11장 포인터 Dynamic Memory and Linked List 1 동적할당메모리의개념 프로그램이메모리를할당받는방법 정적 (static) 동적 (dynamic) 정적메모리할당 프로그램이시작되기전에미리정해진크기의메모리를할당받는것 메모리의크기는프로그램이시작하기전에결정 int i, j; int buffer[80]; char name[] = data structure"; 처음에결정된크기보다더큰입력이들어온다면처리하지못함

More information

Microsoft PowerPoint - [2009] 02.pptx

Microsoft PowerPoint - [2009] 02.pptx 원시데이터유형과연산 원시데이터유형과연산 원시데이터유형과연산 숫자데이터유형 - 숫자데이터유형 원시데이터유형과연산 표준입출력함수 - printf 문 가장기본적인출력함수. (stdio.h) 문법 ) printf( Test printf. a = %d \n, a); printf( %d, %f, %c \n, a, b, c); #include #include

More information

Microsoft PowerPoint - chap11-포인터의활용.pptx

Microsoft PowerPoint - chap11-포인터의활용.pptx #include int main(void) int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; 1 학습목표 포인터를 사용하는 다양한 방법에

More information

4. 1 포인터와 1 차원배열 4. 2 포인터와 2 차원배열 4. 3 포인터배열 4. 4 포인터와문자그리고포인터와문자열

4. 1 포인터와 1 차원배열 4. 2 포인터와 2 차원배열 4. 3 포인터배열 4. 4 포인터와문자그리고포인터와문자열 - Part2-4 4. 1 포인터와 1 차원배열 4. 2 포인터와 2 차원배열 4. 3 포인터배열 4. 4 포인터와문자그리고포인터와문자열 4.1 포인터와 1 차원배열 4.1 1 (1/16)- - - [4-1.c ] #include int main(void) { int array[3]={10, 20, 30}; } prind("%x %x %x

More information

Microsoft PowerPoint - 03_(C_Programming)_(Korean)_Pointers

Microsoft PowerPoint - 03_(C_Programming)_(Korean)_Pointers C Programming 포인터 (Pointers) Seo, Doo-Ok Clickseo.com clickseo@gmail.com 목 차 포인터의이해 다양한포인터 2 포인터의이해 포인터의이해 포인터변수선언및초기화 포인터연산 다양한포인터 3 주소연산자 ( & ) 포인터의이해 (1/4) 변수와배열원소에만적용한다. 산술식이나상수에는주소연산자를사용할수없다. 레지스터변수또한주소연산자를사용할수없다.

More information

ABC 6장

ABC 6장 8 장포인터 김명호 내용 포인터소개 주소연산자 & 포인터변수 역참조연산자 * void 포인터 포인터연산 함수와포인터 메모리사상함수 동적메모리할당 포인터배열 const, restrict 함수포인터 1 포인터 지금까지할당받은메모리공간은변수이름으로접근했었음 예 int a, b, c; a = b + c; // a, b, c 를위한메모리할당 // a, b, c 이름으로메모리접근

More information

Microsoft Word - FunctionCall

Microsoft Word - FunctionCall Function all Mechanism /* Simple Program */ #define get_int() IN KEYOARD #define put_int(val) LD A val \ OUT MONITOR int add_two(int a, int b) { int tmp; tmp = a+b; return tmp; } local auto variable stack

More information

Microsoft PowerPoint - chap13-입출력라이브러리.pptx

Microsoft PowerPoint - chap13-입출력라이브러리.pptx #include int main(void) int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; 1 학습목표 스트림의 기본 개념을 알아보고,

More information

PowerPoint Template

PowerPoint Template 10 포인터 1 주소 Address( 주소 ) 메모리에는그메모리의저장장소의위치를나타내는주소값 주소 (address) 는 1 바이트마다 1 씩증가하도록메모리에는연속적인번호가구성 2 주소연산자 & & 변수 변수의주소값을알아내려면변수앞에주소연산자 & (ampersand) 를이용 주소값이용장단점 주소값을이용하면보다편리하고융통성있는프로그램이가능 그러나복잡하고어려운단점

More information

문서의 제목 나눔명조R, 40pt

문서의 제목  나눔명조R, 40pt 이문서는나눔글꼴로작성되었습니다. 설치하기 11차시 : 함수동적메모리할당다차원배열 프로그래밍및실험 제 11주 동국대학교조영석 6.6 함수인자로써의배열 - 함수정의에서배열로선언된형식매개변수는 pointer임. - 함수의인자로배열이전달되면배열의기본주소가 ( 배열의내용이아님 ) call-by-value로전달됨. - 배열원소는복사되지않음. 2 ( 예 ) #include

More information

02장.배열과 클래스

02장.배열과 클래스 ---------------- DATA STRUCTURES USING C ---------------- CHAPTER 배열과구조체 1/20 많은자료의처리? 배열 (array), 구조체 (struct) 성적처리프로그램에서 45 명의성적을저장하는방법 주소록프로그램에서친구들의다양한정보 ( 이름, 전화번호, 주소, 이메일등 ) 를통합하여저장하는방법 홍길동 이름 :

More information

금오공대 컴퓨터공학전공 강의자료

금오공대 컴퓨터공학전공 강의자료 C 프로그래밍프로젝트 Chap 13. 포인터와배열! 함께이해하기 2013.10.02. 오병우 컴퓨터공학과 13-1 포인터와배열의관계 Programming in C, 정재은저, 사이텍미디어. 9 장참조 ( 교재의 13-1 은읽지말것 ) 배열이름의정체 배열이름은 Compile 시의 Symbol 로서첫번째요소의주소값을나타낸다. Symbol 로서컴파일시에만유효함 실행시에는메모리에잡히지않음

More information

Microsoft PowerPoint - chap06-2pointer.ppt

Microsoft PowerPoint - chap06-2pointer.ppt 2010-1 학기프로그래밍입문 (1) chapter 06-2 참고자료 포인터 박종혁 Tel: 970-6702 Email: jhpark1@snut.ac.kr 한빛미디어 출처 : 뇌를자극하는 C프로그래밍, 한빛미디어 -1- 포인터의정의와사용 변수를선언하는것은메모리에기억공간을할당하는것이며할당된이후에는변수명으로그기억공간을사용한다. 할당된기억공간을사용하는방법에는변수명외에메모리의실제주소값을사용하는것이다.

More information

Microsoft PowerPoint - chap12-고급기능.pptx

Microsoft PowerPoint - chap12-고급기능.pptx #include int main(void) int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; 1 학습목표 가 제공하는 매크로 상수와 매크로

More information

설계란 무엇인가?

설계란 무엇인가? 금오공과대학교 C++ 프로그래밍 jhhwang@kumoh.ac.kr 컴퓨터공학과 황준하 5 강. 배열, 포인터, 참조목차 배열 포인터 C++ 메모리구조 주소연산자 포인터 포인터연산 배열과포인터 메모리동적할당 문자열 참조 1 /20 5 강. 배열, 포인터, 참조배열 배열 같은타입의변수여러개를하나의변수명으로처리 int Ary[10]; 총 10 개의변수 : Ary[0]~Ary[9]

More information

이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다. 2

이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다. 2 제 17 장동적메모리와연결리스트 유준범 (JUNBEOM YOO) Ver. 2.0 jbyoo@konkuk.ac.kr http://dslab.konkuk.ac.kr 본강의자료는생능출판사의 PPT 강의자료 를기반으로제작되었습니다. 이번장에서학습할내용 동적메모리란? malloc() 와 calloc() 연결리스트 파일을이용하면보다많은데이터를유용하고지속적으로사용및관리할수있습니다.

More information

6.1 Addresses and Pointers Recall memory concepts from Ch2 ch6_testbasicpointer.c int x1=1, x2=7; double distance; int *p; int q=8; p = &q; name addre

6.1 Addresses and Pointers Recall memory concepts from Ch2 ch6_testbasicpointer.c int x1=1, x2=7; double distance; int *p; int q=8; p = &q; name addre GEN1031 Computer Programming Chapter 6 Pointer 포인터 Kichun Lee Department of Industrial Engineering Hanyang Univesity 1 6.1 Addresses and Pointers Recall memory concepts from Ch2 ch6_testbasicpointer.c

More information

untitled

untitled while do-while for break continue while( ) ; #include 0 i int main(void) int meter; int i = 0; while(i < 3) meter = i * 1609; printf("%d %d \n", i, meter); i++; return 0; i i< 3 () 0 (1)

More information

Microsoft PowerPoint - 09_C_Language_Pointer_Advanced

Microsoft PowerPoint - 09_C_Language_Pointer_Advanced C Language 포인터응용 Doo-ok Seo clickseo@gmail.com http:// 목 차 다양한포인터 2 차원배열과포인터 동적메모리할당 main() 함수의인자활용 2 다양한포인터 다양한포인터 포인터의포인터 포인터배열 함수포인터 2차원배열과포인터 동적메모리할당 main() 함수의인자활용 3 포인터의포인터 포인터에대한포인터 다루는대상체가포인터인포인터형변수

More information

KNK_C_05_Pointers_Arrays_structures_summary_v02

KNK_C_05_Pointers_Arrays_structures_summary_v02 Pointers and Arrays Structures adopted from KNK C Programming : A Modern Approach 요약 2 Pointers and Arrays 3 배열의주소 #include int main(){ int c[] = {1, 2, 3, 4}; printf("c\t%p\n", c); printf("&c\t%p\n",

More information

< E20C6DFBFFEBEEE20C0DBBCBAC0BB20C0A7C7D12043BEF0BEEE20492E707074>

< E20C6DFBFFEBEEE20C0DBBCBAC0BB20C0A7C7D12043BEF0BEEE20492E707074> Chap #2 펌웨어작성을위한 C 언어 I http://www.smartdisplay.co.kr 강의계획 Chap1. 강의계획및디지털논리이론 Chap2. 펌웨어작성을위한 C 언어 I Chap3. 펌웨어작성을위한 C 언어 II Chap4. AT89S52 메모리구조 Chap5. SD-52 보드구성과코드메모리프로그래밍방법 Chap6. 어드레스디코딩 ( 매핑 ) 과어셈블리어코딩방법

More information

목차 배열의개요 배열사용하기 다차원배열 배열을이용한문자열다루기 실무응용예제 C 2

목차 배열의개요 배열사용하기 다차원배열 배열을이용한문자열다루기 실무응용예제 C 2 제 7 장. 배열 목차 배열의개요 배열사용하기 다차원배열 배열을이용한문자열다루기 실무응용예제 C 2 배열의개요 배열 (array) 의정의 같은데이터형을가지는여러개의변수를하나의배열명으로공유 기억공간을순차적으로할당받아사용하는것 [ 7.1] C 3 배열의개요 배열 (array) 의필요성 같은데이터형의여러개의변수간결하게선언 기억공간을순차적으로변수의값들을저장, 관리

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 오픈소스소프트웨어개발입문 (CP33992) 포인터 부산대학교공과대학정보컴퓨터공학부 학습목표 포인터선언과간접참조를통한포인터사용방법을알수있다. 함수의인수전달에서포인터의역할및사용방법을알수있다. 포인터를통한배열원소의참조방법에대해알수있다. 포인터의가감연산을통한다양한활용법을알수있다. 포인터를이용한문자열처리에대해알수있다. void 포인터, 함수포인터의사용방법을알수있다.

More information

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx

Microsoft PowerPoint - chap02-C프로그램시작하기.pptx #include int main(void) { int num; printf( Please enter an integer "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num = %d\n", num); return 0; } 1 학습목표 을 작성하면서 C 프로그램의

More information

chap10.PDF

chap10.PDF 10 C++ Hello!! C C C++ C++ C++ 2 C++ 1980 Bell Bjarne Stroustrup C++ C C++ C, C++ C C 3 C C++ (prototype) (type checking) C C++ : C++ 4 C C++ (prototype) (type checking) [ 10-1] #include extern

More information

Microsoft PowerPoint - chap06-5 [호환 모드]

Microsoft PowerPoint - chap06-5 [호환 모드] 2011-1 학기프로그래밍입문 (1) chapter 06-5 참고자료 변수의영역과데이터의전달 박종혁 Tel: 970-6702 Email: jhpark1@seoultech.ac.kr h k 한빛미디어 출처 : 뇌를자극하는 C프로그래밍, 한빛미디어 -1- ehanbit.net 자동변수 지금까지하나의함수안에서선언한변수는자동변수이다. 사용범위는하나의함수내부이다. 생존기간은함수가호출되어실행되는동안이다.

More information

Microsoft PowerPoint - chap06-1Array.ppt

Microsoft PowerPoint - chap06-1Array.ppt 2010-1 학기프로그래밍입문 (1) chapter 06-1 참고자료 배열 박종혁 Tel: 970-6702 Email: jhpark1@snut.ac.kr 한빛미디어 출처 : 뇌를자극하는 C프로그래밍, 한빛미디어 -1- 배열의선언과사용 같은형태의자료형이많이필요할때배열을사용하면효과적이다. 배열의선언 배열의사용 배열과반복문 배열의초기화 유연성있게배열다루기 한빛미디어

More information

Microsoft PowerPoint - chap6 [호환 모드]

Microsoft PowerPoint - chap6 [호환 모드] 제 6 장프로세스 (Process) 숙대창병모 1 내용 프로세스시작 / 종료 명령중인수 / 환경변수 메모리배치 / 할당 비지역점프 숙대창병모 2 프로세스시작 / 종료 숙대창병모 3 Process Start Kernel exec system call user process Cstart-up routine call return int main(int argc,

More information

Microsoft PowerPoint - chap06.ppt

Microsoft PowerPoint - chap06.ppt 2010-1 학기프로그래밍입문 (1) 6 장배열, 포인터, 문자열 박종혁 Tel: 970-6702 Email: jhpark1@snut.ac.kr 0 목차 6.1 1차원배열 6.2 포인터 6.3 참조에의한호출 6.4 배열과포인터의관계 6.5 포인터연산과원소크기 6.6 함수인자로서의배열 6.7 예제 : 버블정렬 6.8 calloc() 과 malloc() 을이용한동적메모리할당

More information

OCW_C언어 기초

OCW_C언어 기초 초보프로그래머를위한 C 언어기초 4 장 : 연산자 2012 년 이은주 학습목표 수식의개념과연산자및피연산자에대한학습 C 의알아보기 연산자의우선순위와결합방향에대하여알아보기 2 목차 연산자의기본개념 수식 연산자와피연산자 산술연산자 / 증감연산자 관계연산자 / 논리연산자 비트연산자 / 대입연산자연산자의우선순위와결합방향 조건연산자 / 형변환연산자 연산자의우선순위 연산자의결합방향

More information

Microsoft PowerPoint - 제3장-배열.pptx

Microsoft PowerPoint - 제3장-배열.pptx 제 3 강. 배열 (Array) 자료구조 1 제 3 강. 배열자료구조 학습목차 1. 배열의개념 2. 구조체 3. 희소 (Sparce) 행렬 4. 다차원배열의저장 2 1. 배열의개념 리스트는일상생활에서가장많이쓰이는자료형태이다. 예 ) 학생의명단, 은행거래고객명단, 월별판매액등 배열 (Array) 은컴퓨터언어에서리스트를저장하는데이터타입이다. 리스트와배열은같은개념이지만다른차원의용어이다.

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Chapter 08 함수 01 함수의개요 02 함수사용하기 03 함수와배열 04 재귀함수 함수의필요성을인식한다. 함수를정의, 선언, 호출하는방법을알아본다. 배열을함수의인자로전달하는방법과사용시장점을알아본다. 재귀호출로해결할수있는문제의특징과해결방법을알아본다. 1.1 함수의정의와기능 함수 (function) 특별한기능을수행하는것 여러가지함수의예 Page 4 1.2

More information

<4D F736F F F696E74202D20C1A63132B0AD20B5BFC0FB20B8DEB8F0B8AEC7D2B4E7>

<4D F736F F F696E74202D20C1A63132B0AD20B5BFC0FB20B8DEB8F0B8AEC7D2B4E7> 제14장 동적 메모리 할당 Dynamic Allocation void * malloc(sizeof(char)*256) void * calloc(sizeof(char), 256) void * realloc(void *, size_t); Self-Referece NODE struct selfref { int n; struct selfref *next; }; Linked

More information

3. 1 포인터란 3. 2 포인터변수의선언과사용 3. 3 다차원포인터변수의선언과사용 3. 4 주소의가감산 3. 5 함수포인터

3. 1 포인터란 3. 2 포인터변수의선언과사용 3. 3 다차원포인터변수의선언과사용 3. 4 주소의가감산 3. 5 함수포인터 - Part2-3 3. 1 포인터란 3. 2 포인터변수의선언과사용 3. 3 다차원포인터변수의선언과사용 3. 4 주소의가감산 3. 5 함수포인터 3.1 포인터란 ü ü ü. ü. ü. ü ( ) ? 3.1 ü. ü C ( ).? ü ü PART2-4 ü ( ) PART3-4 3.2 포인터변수의선언과사용 3.2 포인터 변수의 선언과 사용 (1/8) 포인터 변수의

More information

구조체정의 자료형 (data types) 기본자료형 (primitive data types) : char, int, float 등과같이 C 언어에서제공하는자료형. 사용자정의자료형 (user-defined data types) : 다양한자료형을묶어서목적에따라새로운자료형을

구조체정의 자료형 (data types) 기본자료형 (primitive data types) : char, int, float 등과같이 C 언어에서제공하는자료형. 사용자정의자료형 (user-defined data types) : 다양한자료형을묶어서목적에따라새로운자료형을 (structures) 구조체정의 구조체선언및초기화 구조체배열 구조체포인터 구조체배열과포인터 구조체와함수 중첩된구조체 구조체동적할당 공용체 (union) 1 구조체정의 자료형 (data types) 기본자료형 (primitive data types) : char, int, float 등과같이 C 언어에서제공하는자료형. 사용자정의자료형 (user-defined

More information

chap7.key

chap7.key 1 7 C 2 7.1 C (System Calls) Unix UNIX man Section 2 C. C (Library Functions) C 1975 Dennis Ritchie ANSI C Standard Library 3 (system call). 4 C?... 5 C (text file), C. (binary file). 6 C 1. : fopen( )

More information

Microsoft Word - ExecutionStack

Microsoft Word - ExecutionStack Lecture 15: LM code from high level language /* Simple Program */ external int get_int(); external void put_int(); int sum; clear_sum() { sum=0; int step=2; main() { register int i; static int count; clear_sum();

More information

Microsoft PowerPoint - chap06-8 [호환 모드]

Microsoft PowerPoint - chap06-8 [호환 모드] 2011-1 학기프로그래밍입문 (1) 참고자료 chap 6-8. 메모리동적할당 박종혁 Tel: 970-6702 Email: jhpark1@seoultech.ac.kr h k 한빛미디어 출처 : 뇌를자극하는 C프로그래밍, 한빛미디어 -1- ehanbit.net 동적할당의필요성 프로그램을작성하는단계에서필요한기억공간의크기를결정하는 것은정적할당이다. - 변수나배열의선언

More information

슬라이드 1

슬라이드 1 정적메모리할당 (Static memory allocation) 일반적으로프로그램의실행에필요한메모리 ( 변수, 배열, 객체등 ) 는컴파일과정에서결정되고, 실행파일이메모리에로드될때할당되며, 종료후에반환됨 동적메모리할당 (Dynamic memory allocation) 프로그램의실행중에필요한메모리를할당받아사용하고, 사용이끝나면반환함 - 메모리를프로그램이직접관리해야함

More information

C 프로그래밊 개요

C 프로그래밊 개요 함수 (2) 2009 년 9 월 24 일 김경중 공지사항 10 월 1 일목요일수업휴강 숙제 #1 마감 : 10 월 6 일화요일 기초 함수를만들어라! 입력 함수 ( 기능수행 ) 반환 사용자정의함수 정의 : 사용자가자신의목적에따라직접작성한함수 함수의원형 (Function Prototype) + 함수의본체 (Function Body) : 함수의원형은함수에대한기본적정보만을포함

More information

본 강의에 들어가기 전

본 강의에 들어가기 전 C 기초특강 종합과제 과제내용 구조체를이용하여교과목이름과코드를파일로부터입력받아관리 구조체를이용하여학생들의이름, 학번과이수한교과목의코드와점수를파일로부터입력 학생개인별총점, 평균계산 교과목별이수학생수, 총점및평균을계산 결과를파일에저장하는프로그램을작성 2 Makefile OBJS = score_main.o score_input.o score_calc.o score_print.o

More information

강의10

강의10 Computer Programming gdb and awk 12 th Lecture 김현철컴퓨터공학부서울대학교 순서 C Compiler and Linker 보충 Static vs Shared Libraries ( 계속 ) gdb awk Q&A Shared vs Static Libraries ( 계속 ) Advantage of Using Libraries Reduced

More information

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션 Chapter 15 고급프로그램을 만들기위한 C... 1. main( ) 함수의숨겨진이야기 2. 헤더파일 3. 전처리문과예약어 1. main( ) 함수의숨겨진이야기 main( ) 함수의매개변수 [ 기본 14-1] main( ) 함수에매개변수를사용한예 1 01 #include 02 03 int main(int argc, char* argv[])

More information

ABC 6장

ABC 6장 6 장배열, 포인터, 문자열 0 1 차원배열 배열 : 첨자가붙은변수를사용하고여러개의동질적값을표현할수있는자료형 예 ( 성적처리를위한변수선언 ) int int grade0, grade1, grade2; grade[3]; 1 차원배열선언 int a[size]; - lower bound = 0 - upper bound = size - 1 - size = upper

More information

C++ Programming

C++ Programming C++ Programming 연산자다중정의 Seo, Doo-okok clickseo@gmail.com http://www.clickseo.com 목 차 연산자다중정의 C++ 스타일의문자열 2 연산자다중정의 연산자다중정의 단항연산자다중정의 이항연산자다중정의 cin, cout 그리고 endl C++ 스타일의문자열 3 연산자다중정의 연산자다중정의 (Operator

More information

Chapter 4. LISTS

Chapter 4. LISTS C 언어에서리스트구현 리스트의생성 struct node { int data; struct node *link; ; struct node *ptr = NULL; ptr = (struct node *) malloc(sizeof(struct node)); Self-referential structure NULL: defined in stdio.h(k&r C) or

More information

Microsoft PowerPoint - chap03-변수와데이터형.pptx

Microsoft PowerPoint - chap03-변수와데이터형.pptx #include int main(void) { int num; printf( Please enter an integer: "); scanf("%d", &num); if ( num < 0 ) printf("is negative.\n"); printf("num %d\n", num); return 0; } 1 학습목표 의 개념에 대해 알아본다.

More information

Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3

Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3 Poison null byte Excuse the ads! We need some help to keep our site up. List 1 Conditions 2 Exploit plan 2.1 chunksize(p)!= prev_size (next_chunk(p) 3 Example 3.1 Files 3.2 Source code 3.3 Exploit flow

More information

Microsoft PowerPoint - chap06-8.ppt

Microsoft PowerPoint - chap06-8.ppt 2010-1 학기프로그래밍입문 (1) 참고자료 chap 6-8. 메모리동적할당 박종혁 Tel: 970-6702 Email: jhpark1@snut.ac.kr 한빛미디어 출처 : 뇌를자극하는 C프로그래밍, 한빛미디어 -1- 동적할당의필요성 프로그램을작성하는단계에서필요한기억공간의크기를결정하는것은정적할당이다. - 변수나배열의선언 프로그램의실행중에입력되는데이터에맞게기억공간을확보해야할때는동적할당이필요하다.

More information

Microsoft PowerPoint - C_9장 포인터 pptx

Microsoft PowerPoint - C_9장 포인터 pptx C 프로그래밍및실습 9. 포인터 세종대학교 목차 1) 포인터란? 2) 배열과포인터 3) 포인터연산 4) 함수와포인터 5) * void 포인터 6) * 함수포인터 2 1) 포인터란? 메모리 프로그램이실행되기위해필요한정보 ( 값 ) 을저장하는공간 1 byte (8 bits) 단위로물리주소가부여되어있음 개념적으로, 메모리는일렬로연속되어있는크기가 1byte 인방들의모음이라고볼수있음

More information

K&R2 Reference Manual 번역본

K&R2 Reference Manual 번역본 typewriter structunion struct union if-else if if else if if else if if if if else else ; auto register static extern typedef void char short int long float double signed unsigned const volatile { } struct

More information

11장 포인터

11장 포인터 누구나즐기는 C 언어콘서트 제 13 장전처리및기타기능 이번장에서학습할내용 전처리지시어 분할컴파일 명령어라인의매개변수 디버깅방법 전처리와기타중요한테마에대하여학습한다. 전처리기란? 전처리기 (preprocessor) 는컴파일하기에앞서서소스파일을처리하는컴파일러의한부분 전처리기의요약 지시어 #define #include #undef #if #else #endif #ifdef

More information

Chapter 4. LISTS

Chapter 4. LISTS 연결리스트의응용 류관희 충북대학교 1 체인연산 체인을역순으로만드는 (inverting) 연산 3 개의포인터를적절히이용하여제자리 (in place) 에서문제를해결 typedef struct listnode *listpointer; typedef struct listnode { char data; listpointer link; ; 2 체인연산 체인을역순으로만드는

More information

<4D F736F F F696E74202D20C1A63137C0E520B5BFC0FBB8DEB8F0B8AEBFCD20BFACB0E1B8AEBDBAC6AE>

<4D F736F F F696E74202D20C1A63137C0E520B5BFC0FBB8DEB8F0B8AEBFCD20BFACB0E1B8AEBDBAC6AE> 쉽게풀어쓴 C 언어 Express 제 17 장동적메모리와연결리스트 이번장에서학습할내용 동적메모리할당의이해 동적메모리할당관련함수 연결리스트 동적메모리할당에대한개념을이해하고응용으로연결리스트를학습합니다. 동적할당메모리의개념 프로그램이메모리를할당받는방법 정적 (static) 동적 (dynamic) 정적메모리할당 정적메모리할당 프로그램이시작되기전에미리정해진크기의메모리를할당받는것

More information

歯7장.PDF

歯7장.PDF 7 Hello!! C 2 . 3 ([] ) < > [ ]; int array[10]; < > [ ][ ]; int array [3] [5]; 4 < > [ ]={ x1,,x10} ( ); (,). ({}). : int array[10]={1,2,3,4,5,6,7,8,9,10}; (" "). : char array[7]="turbo-c"; 5 int array[2][3]={{1,2},{3,4},{5,6}};

More information

chap7.PDF

chap7.PDF 7 Hello!! C 2 . 3 ([] ) < > [ ]; int array[10]; < > [ ][ ]; int array [3] [5]; 4 < > [ ]={ x1,,x10} ( ); (,). ({}). : int array[10]={1,2,3,4,5,6,7,8,9,10}; (" "). : char array[7]="turbo-c"; 5 int array[2][3]={{1,2},{3,4},{5,6}};

More information

1. 표준입출력 C++ : C의모든라이브러리를포함 printf, scanf 함수사용가능예 : int, double, 문자열값을입력받고출력하기 #include <cstdio> int ivar; double dvar; char str[20]; printf("int, dou

1. 표준입출력 C++ : C의모든라이브러리를포함 printf, scanf 함수사용가능예 : int, double, 문자열값을입력받고출력하기 #include <cstdio> int ivar; double dvar; char str[20]; printf(int, dou 2 장더나은 C 로서의 C++ (1) 표준입출력네임스페이스 ( 고전 C++ 와표준 C++) 함수오버로딩디폴트매개변수 new와 delete bool 자료형 C++ is not C C++ 프로그래밍입문 1. 표준입출력 C++ : C의모든라이브러리를포함 printf, scanf 함수사용가능예 : int, double, 문자열값을입력받고출력하기 #include

More information

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100

Microsoft PowerPoint - ch09 - 연결형리스트, Stack, Queue와 응용 pm0100 2015-1 프로그래밍언어 9. 연결형리스트, Stack, Queue 2015 년 5 월 4 일 교수김영탁 영남대학교공과대학정보통신공학과 (Tel : +82-53-810-2497; Fax : +82-53-810-4742 http://antl.yu.ac.kr/; E-mail : ytkim@yu.ac.kr) 연결리스트 (Linked List) 연결리스트연산 Stack

More information

Microsoft PowerPoint - 05-chap03-ArrayAndPointer.ppt

Microsoft PowerPoint - 05-chap03-ArrayAndPointer.ppt 배열이란? Chapter. 배열구조체포인터 같은형의변수를여러개만드는경우에사용 int A, A, A, A,, A; int A[]; 4 5 6 반복코드등에서배열을사용하면효율적인프로그래밍이가능 예 ) 최대값을구하는프로그램 : 만약배열이없었다면? tmp=score[]; for(i=;i tmp ) tmp = score[i]; Today...

More information

Microsoft PowerPoint - C++ 5 .pptx

Microsoft PowerPoint - C++ 5 .pptx C++ 언어프로그래밍 한밭대학교전자. 제어공학과이승호교수 연산자중복 (operator overloading) 이란? 2 1. 연산자중복이란? 1) 기존에미리정의되어있는연산자 (+, -, /, * 등 ) 들을프로그래머의의도에맞도록새롭게정의하여사용할수있도록지원하는기능 2) 연산자를특정한기능을수행하도록재정의하여사용하면여러가지이점을가질수있음 3) 하나의기능이프로그래머의의도에따라바뀌어동작하는다형성

More information

Microsoft PowerPoint - additional01.ppt [호환 모드]

Microsoft PowerPoint - additional01.ppt [호환 모드] 1.C 기반의 C++ part 1 함수 오버로딩 (overloading) 디폴트매개변수 (default parameter) 인-라인함수 (in-line function) 이름공간 (namespace) Jong Hyuk Park 함수 Jong Hyuk Park 함수오버로딩 (overloading) 함수오버로딩 (function overloading) C++ 언어에서는같은이름을가진여러개의함수를정의가능

More information

BMP 파일 처리

BMP 파일 처리 BMP 파일처리 김성영교수 금오공과대학교 컴퓨터공학과 학습내용 영상반전프로그램제작 2 Inverting images out = 255 - in 3 /* 이프로그램은 8bit gray-scale 영상을입력으로사용하여반전한후동일포맷의영상으로저장한다. */ #include #include #define WIDTHBYTES(bytes)

More information

11장 포인터

11장 포인터 쉽게풀어쓴 C 언어 Express 제 12 장문자와문자열 이번장에서학습할내용 문자표현방법 문자열표현방법 문자열이란무엇인가? 문자열의입출력 문자처리라이브러리함수 표준입출력라이브러리함수 인간은문자를사용하여정보를표현하므로문자열은프로그램에서중요한위치를차지하고있다. 이번장에서는 C 에서의문자열처리방법에대하여자세히살펴볼것이다. 문자의중요성 인간한테텍스트는대단히중요하다.

More information

untitled

untitled if( ) ; if( sales > 2000 ) bonus = 200; if( score >= 60 ) printf(".\n"); if( height >= 130 && age >= 10 ) printf(".\n"); if ( temperature < 0 ) printf(".\n"); // printf(" %.\n \n", temperature); // if(

More information

중간고사

중간고사 중간고사 예제 1 사용자로부터받은두개의숫자 x, y 중에서큰수를찾는알고리즘을의사코드로작성하시오. Step 1: Input x, y Step 2: if (x > y) then MAX

More information

C 언어 프로그래밊 과제 풀이

C 언어 프로그래밊 과제 풀이 과제풀이 (1) 홀수 / 짝수판정 (1) /* 20094123 홍길동 20100324 */ /* even_or_odd.c */ /* 정수를입력받아홀수인지짝수인지판정하는프로그램 */ int number; printf(" 정수를입력하시오 => "); scanf("%d", &number); 확인 주석문 가필요한이유 printf 와 scanf 쌍

More information

Microsoft PowerPoint - 05장(함수) [호환 모드]

Microsoft PowerPoint - 05장(함수) [호환 모드] 이장에서다룰내용 1 함수의기본 2 함수의입출력방법 함수 함수는입력을넣으면출력이나오는마술상자다. 3 4 재귀함수 Inline 함수 01_ 함수의기본 01_ 함수의기본 함수란 함수를사용할때의장점 반복적으로실행해야할내용을함수로만들어필요할때마다호출해사용할수있다. 프로그램이모듈화 ( 블록화 ) 되므로읽기쉽고, 디버그와편집이쉽다. 프로그램의기능과구조을한눈에알아보기쉽다.

More information

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt 변수와상수 1 변수란무엇인가? 변수 : 정보 (data) 를저장하는컴퓨터내의특정위치 ( 임시저장공간 ) 메모리, register 메모리주소 101 번지 102 번지 변수의크기에따라 주로 byte 단위 메모리 2 기본적인변수형및변수의크기 변수의크기 해당컴퓨터에서는항상일정 컴퓨터마다다를수있음 short

More information

Microsoft PowerPoint - 9ÀÏ°_ÂüÁ¶ÀÚ.ppt

Microsoft PowerPoint - 9ÀÏ°_ÂüÁ¶ÀÚ.ppt 참조자 - 참조자란무엇인가? - 참조자는어떻게만들고사용하는가? - 참조자는포인터와무엇이다른가? 1 참조자 (reference) 란? 참조자 : 객체 ( 타겟 ) 에대한다른이름 ( 별칭 ) 참조자의변화는타겟의변화 참조자만들고반드시초기화 참조자생성 형참조연산자 (&) 참조자이름 = 초기화타겟명 모든항목필수 예 ) int &rsomeref = someint ; 참조자에대한주소연산자

More information

Microsoft PowerPoint - Chapter_04.pptx

Microsoft PowerPoint - Chapter_04.pptx 프로그래밍 1 1 Chapter 4. Constant and Basic Data Types April, 2016 Dept. of software Dankook University http://embedded.dankook.ac.kr/~baeksj 이장의강의목표 2 기본자료형문자표현방식과문자자료형상수자료형변환 기본자료형 (1/8) 3 변수 (Variables)

More information