코스웨어/14년 스마트컨트롤러
20140414 업무일지 김재성 출석번호 7
알 수 없는 사용자
2014. 4. 14. 22:40








연결 리스트
#include <stdio.h>
struct smart { int iNum; struct smart * self; };
int main() { struct smart A = {1, 0}; struct smart B = {2, 0}; struct smart C = {3, 0}; struct smart D = {4, 0}; struct smart * p; A.self = &B; B.self = &C; C.self = &D; p = &A; 최초 p는 A의 주소를 가리킴요
while(0 != p) { printf("%d->", p->iNum); p = p->self; p->self값은 다음주소를 가르키져? } printf("NULL \n"); return 0; }

|
#include <stdio.h>
struct bigdata { int iNum; char data[1000]; struct bigdata * next; };
int main() { struct bigdata test[4]; struct bigdata temp; struct bigdata * p; int iCnt;
test[0].iNum = 0; test[1].iNum = 1; test[2].iNum = 2; test[3].iNum = 3;
test[0].next = &test[1]; 연결리스트 test[1].next = &test[2]; test[2].next = &test[3]; test[3].next = 0;
for(iCnt=0; 4>iCnt; iCnt++) { printf("%d->", test[iCnt].iNum); }
// temp.iNum = test[0].iNum; 구조체가 10메가면 어쩔래? 아래의 노란펜 포인터로 쓰면 간단(ㅜ.ㅜ)하다. // test[0].iNum = test[1].iNum; // test[1].iNum = temp.iNum;
printf("\n"); for(iCnt=0; 4>iCnt; iCnt++) { printf("%d->", test[iCnt].iNum); }
printf("\n"); for(p=test; p!=0; p=p->next) 위에서 한것과 똑같다. { printf("%d->", p->iNum); } printf("\n");
p = &test[1]; test[0].next = &test[2]; p->next = test[2].next; test[2].next = p;
for(p=test; p!=0; p=p->next) { printf("%d->", p->iNum); }
return 0;
}
위의 노란펜부분의 메모리 구조 예시

|

변수선언으러 보는 메모리 다섯가지 구조
포인터 기본기 많이 쌓아야할듯 ㅈㅅ



즐감요! ㅋㅋㅋㅋㅋㅋㅋ