C
(C언어) 구조체 예제
SAFE
2016. 4. 28. 17:43
구조체
struct soso{ <<<- 이름
멤버
};
구조체 간단한 예제 .x .y 이렇게 쓰면 됩니다.
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 | #include <stdio.h> struct son{ //구조체 만들 때 이렇게 쓴다. int x; int y; }; int main(void){ struct son p1,p2,p3; //만들 때 이렇게 쓴다. // p1에게 son의 틀 주소값 넘겨줌 printf("%x %x %x \n",p1,p2,p3); // 각자 다른 공간이 생김 /* p1 p2 p3 [] [] [] */ p1.x = 10; p1.y = 20; p2.x = 100; p2.y = 200; p3.x=1000; p3.y=1000; printf("%d %d \n", p1.x, p1.y); printf("%d %d \n", p2.x, p2.y); printf("%d %d \n", p3.x, p3.y); return 0; } | cs |
예제 실행