영어로 읽는 코딩

32 [C] 포인터배열

Pointer Arrays: Pointers to Pointers

 

char *lineptr[MAXLINES]

 

says that lineptr is an array of MAXLINES elements, each element of which is a pointer to a char. That is, lineptr [i] is a character pointer, and *lineptr[i] is the character it points to, the first character of the i-th saved text line.

 

Since lineptr is itself the name of an array, it can be treated as a pointer in the same manner as in our earlier examples, and writelines can be written instead as

 

/* writelines: write output lines */

void writelines(char *lineptr[], int nlines)

{

    while (nlines-- > 0)

           printf(”%s\n”, *lineptr++);

}

 

Initially *lineptr points to the first line; each increment advances it to the next line pointer while nlines is counted down.

 

[The C Programming Language p.109]

댓글

댓글 본문
버전 관리
Yoo Moon Il
현재 버전
선택 버전
graphittie 자세히 보기