typedef struct _node = typedef struct _node {int iNum;}NODE;
{
int iNum;
}NODE;
{
int iNum;
}NODE;
왼쪽의 구조체를 바꾸면 오른쪽과 같습니다
이것은 typedef의 형을 보면 쉽게 이해할수 있습니다
typedef oldtype newtype;
즉
typedef struct _node {int iNum;} NODE;
[oldtype] [newtype]
[oldtype] [newtype]
값을 연결하여 전달하는 두가지 방법
1) 똑같이 반복되어 코드가 수월해진다
p = &one;
printf("\n");
printf("%d->",p->iNum);
p=p->next;
printf("%d->",p->iNum);
p=p->next;
printf("%d->",p->iNum);
p=p->next;
printf("NULL\n");
printf("\n");
printf("%d->",p->iNum);
p=p->next;
printf("%d->",p->iNum);
p=p->next;
printf("%d->",p->iNum);
p=p->next;
printf("NULL\n");
2) 변수가 추가되면 printf문의 길이가 길어진다 하지만 1)보다는 간결하다
printf("%d->",one.iNum);
printf("%d->",one.next->iNum);
printf("%d->",one.next->next->iNum);
printf("NULL\n");
printf("%d->",one.next->iNum);
printf("%d->",one.next->next->iNum);
printf("NULL\n");
자기참조포인터
typedef struct _node
{
int iNum;
struct _node *next;
}NODE;
{
int iNum;
struct _node *next;
}NODE;
: 구조체가 자기 자신을 가리키는 포인터
과제1)
array[4] = {5,1,4,2,3} 를 1,2,3,4,5 그리고 5,4,3,2,1로 순서대로 출력하기
#include <stdio.h> |
결과
'Daily Report' 카테고리의 다른 글
110714 저수준함수 + 연결리스트 / at91sam7s CLCD세팅 (0) | 2011.07.14 |
---|---|
110711 연결리스트 prev / ARM LCD SPEC (0) | 2011.07.11 |
110705 함수포인터 반환형 / 포인터형 변수선언 / 문제 (0) | 2011.07.05 |
110630 고수준 fprintf() fwrite() 차이 (0) | 2011.07.01 |
110629 소켓통신의 흐름 / 소켓의 생성 및 해제 / memset (0) | 2011.06.30 |