Q: What are pointers really good for, anyway?
A: They're good for lots of things, such as:
- dynamically-allocated arrays (see questions 6.14 and 6.16)
- generic access to several similar variables
- (simulated) by-reference function parameters (see question 4.8 and 20.1)
- malloc'ed data structures of all kinds, especially trees and linked lists
- walking over arrays (for example, while parsing strings)
- efficient, by-reference ``copies'' of arrays and structures, especially as function parameters
(Note that this is hardly a comprehensive list!)
See also question 6.8.
반응형
'엔지니어' 카테고리의 다른 글
C FAQ (포인터 증가 2) (7) | 2012.07.12 |
---|---|
C FAQ (포인터 증가에 대해서) (7) | 2012.07.12 |
C FAQ (malloc 오류) (7) | 2012.07.12 |
C FAQ (포인터 선언 에러) (7) | 2012.07.12 |
[Linux/Unix]포트가 열렸는지 여부확인 (166) | 2012.07.12 |