Dailelog

structure 본문

언어/C언어

structure

Daile 2022. 6. 25. 15:33
구조체 (structure)
서로 밀접한 연관이 있는 변수들을 모아 놓은 복합 변수 -> 나중에 "객체"라고 지칭함

cf.배열
*/
#include <stdio.h>
struct point {
int x;
int y;
};
void findCenterPoint(struct point *p,struct point q,struct point r)
{
p->x = (q.x + r.x) / 2;
p->y = (q.y + r.y) / 2;
}
void printPoint(char *name,struct point p)
{
printf("%s = (%d,%d)\n",name,p.x,p.y);
}
main()
{
struct point a;
struct point b;
struct point c;
a.x = 10;
a.y = 10;
b.x = 20;
b.y = 30;
findCenterPoint(&c,a,b);
printPoint("a",a);
printPoint("b",b);
printPoint("c",c);
}
/* 결과는 다음과 같이 나온다.
a = (10,10)
b = (20,30)
c = (15,20)
*/
  • © 2022 GitHub, Inc.
LIST

'언어 > C언어' 카테고리의 다른 글

C_2차원 배열 Dynamic alloction  (0) 2022.05.07
C_dynamic allocation  (1) 2022.05.03
C_string_strcmp  (0) 2022.04.27
C_string_strcpy  (0) 2022.04.27
C_포인터 사용 목적  (1) 2022.04.26