Skip to content

Commit 33322d6

Browse files
committed
Update struct using pointer
1 parent 6a72db3 commit 33322d6

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

struct

-8 Bytes
Binary file not shown.

struct.c

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ int main(int argc, char *argv[]) {
99
char id[20];
1010
};
1111

12-
struct student s1;
12+
struct student *s1;
13+
s1 = (struct student *)malloc(sizeof(struct student));
14+
1315
printf("Enter name: ");
14-
scanf("%s", s1.name);
16+
scanf("%s", s1->name);
1517
printf("Enter age: ");
16-
scanf("%d", &s1.age);
18+
scanf("%d", &s1->age);
1719
printf("Enter id: ");
18-
scanf("%s", s1.id);
20+
scanf("%s", s1->id);
1921

20-
printf("Name: %s\n", s1.name);
21-
printf("Age: %d\n", s1.age);
22-
printf("Id: %s\n", s1.id);
22+
printf("Name: %s\n", s1->name);
23+
printf("Age: %d\n", s1->age);
24+
printf("Id: %s\n", s1->id);
2325

2426
return 0;
2527
}

0 commit comments

Comments
 (0)