|
죄송합니다. 궁금한게 있어서 이렇게 질문을 올립니다.
밑의 코딩중에 disp()에서 printf("%15s%5d\n",name,age);이것이 왜들어있는지를잘
모르겠습니다.
그밑에 보면 while문으로 똑같은게 출력되는게 있는데 말이져..
아직 초보라서 잘모릅니다. 자세히 설명부탁합니다.
아! 이거 출력결과는 main함수에 입력된거 두번찍히는게 결과입니다.
그럼 즐거운 하루되세요
#include <stdio.h>
#include <string.h>
class Person{
char name[12];
int age;
Person *next;
public:
Person (char *p="",int y=0,Person *q=NULL)
{
strcpy(name,p); age =y;next=q;
}
void disp();
};
void Person ::disp ()
{
Person *p;
printf("%15s%5d\n",name,age);
p=next;
while(p!=NULL) {
printf("%15s%5d\n",p->name,p->age);
p=p->next ;
}
}
void main(void)
{
Person a("ANN",21,NULL);
Person b("Candy",18,&a);
Person c("Rolla",20,&b);
Person *head =&c;
head->disp ();
c.disp ();
}
|