구조체 포인터


구조체 포인터

이번에는 구조체 포인터를 이용한 선언입니다. #include <stdio.h> #include <string.h> typedef struct Student Student; struct Student{ char name[32]; int score; }; int main(){ Student s; Student *p; // Student 구조체에 대한 포인터 변수 p=&s; // Student 구조체 변수 s의 주소를 포인터 변수 p에 저장 strcpy(p->name, "Gil-dong Hong"); // s를 이용했을 땐 s.name이지만 p를 이용할 땐 p->name 형태로 p->score= 95; printf("Name : %s\n", p->name); printf("Score: %d\n", p->score); return 0; } 지난 게시물과 같은 결과가 나옵니다. 아래는 printInfo함수를 만든 프로그램입니다. #include <stdio.h> #include <string...


#c언어 #구조체포인터 #자료구조

원문링크 : 구조체 포인터