[10] 구조체


[10] 구조체

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 #include <stdio.h> #include <stdlib.h> struct S1 { int p1,p2; }; struct S2 { int p1; struct S1 s1; int p2; }; int main(void) { int s = 0; struct S2 s2 = { 1, 2, 3, 4 }; struct S2 *p; p = (struct S2 *)malloc(sizeof(struct S2)); *p = s2; s2. p1 = 0; s = p->p1 + s2.p1 + p->p2 + p->s1.p2; free(p); printf("%d",s); return 0; } Colored by Color Scripter cs 출력 결과 : 8 struct S2 s2 = { 1, 2, 3, 4 }; 으로 인해서 p1 = 1; s1.p1 = 2; s1.p2 = 3; p2 =...



원문링크 : [10] 구조체