[7급 국가직 자료구조론 2016년 13번]

다음은 동적 메모리 할당을 통해 구조체 공간을 확보하고 이름과 학번을 입력받아 구조체에 저장하는 C 언어 함수이다. ㉠, ㉡에 들어갈 내용으로 옳게 짝지어진 것은?
#include <stdio.h>
#include <stdlib.h>

struct student{
   char name[20];
   int id;
};

struct student *alloc()
{
   struct student *p;
   p =        ㉠        ;
   if(p==NULL){
      printf("Memory allocation error.");
      return p;
   }
   printf("Student name?\n");
   gets(p->name);
   printf("Student id?\n");
   scanf("%d",    ㉡   );
   return p;
}
㉠ ㉡
자료구조론
  1. ①(struct student)malloc(sizeof(struct student)) &((*p).id)
  2. ②(struct student *)malloc(sizeof(struct student)) p->id
  3. ③(struct student)malloc(sizeof(struct student)) (*p).id
  4. ④(struct student *)malloc(sizeof(struct student)) &(p->id)

선지를 골라 바로 채점해 보세요.

정답 ④

출처: 인사혁신처 공개 기출(공공데이터포털, 이용허락 제한 없음)

신고가 접수됐습니다. 감사합니다.

오류 신고