-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweak2_struct3.cpp
More file actions
45 lines (35 loc) · 940 Bytes
/
weak2_struct3.cpp
File metadata and controls
45 lines (35 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MALE 0
#define FEMALE 1
//구조체 포인터 사용
struct Person {
char name[20];
int age;
char gender;
char major[20];
} ;
int main() {
struct Person p1;
struct Person *ptr;
ptr = &p1;
strcpy(ptr->name, "김철수");
ptr->age = 27;
ptr-> gender = MALE;
strcpy(ptr->major, "전자공학");
printf("이름: %s\n", ptr->name);
printf("나이: %d\n", ptr->age);
printf("성별: %s\n", (ptr->gender==0) ? "남" : "여");
printf("전공: %s\n", ptr->major);
strcpy(ptr->name, "나영희");
ptr->age = 23;
ptr-> gender = FEMALE;
strcpy(ptr->major, "경영학과");
printf("이름: %s\n", ptr->name);
printf("나이: %d\n", ptr->age);
printf("성별: %s\n", (ptr->gender==0) ? "남" : "여");
printf("전공: %s\n", ptr->major);
free(ptr);
return 0;
}