#include <stdio.h>


typedef struct point
{
  int xpos;
  int ypos;
} Point;


int main()
{
  Point pos1={12};

  Point pos2;
  pos2 = pos1;                           //구조체의 대입연산이 되는가?

  printf("크기: %d \n"sizeof(pos1));  //구조체의 sizeof연산이 되는가?
  printf("%d %d \n"pos1.xpos, pos1.ypos);


  printf("크기: %d \n"sizeof(pos2));  //구조체에 대입연산이 되었는가?
  printf("%d %d \n"pos2.xpos, pos2.ypos);



  return 0;
}


 #include <stdio.h>


typedef struct point
{
  int xpos;
  int ypos;
} Point;    //Point구조체 선언

Point AddPoint(Point pos1, Point pos2)  //구조체 덧셈을 가능하게하는 함수
{
  Point pos={pos1.xpos+pos2.xpos, pos1.ypos+pos2.ypos};
  return pos;
}
Point MinPoint(Point pos1, Point pos2)  //구조체 뺄셈을 가능하게하는 함수
{
  Point pos={pos1.xpos-pos2.xpos, pos1.ypos-pos2.ypos};
  return pos;

}

int main()
{
  Point pos1={56};  
  Point pos2={29};
  Point result;

  result=AddPoint(pos1, pos2);
  printf("[%d, %d] \n", result.xpos, result.ypos);
  result=MinPoint(pos1, pos2);
  printf("[%d, %d] \n", result.xpos, result.ypos);
  return 0;
}


 #include <stdio.h>


typedef struct _Point
{
  int xpos;
  int ypos;
} point;

typedef struct _Circle
{
  point cen;  //구조체의 변수를 선언
  double rad;
} circle;

void ShowCircleInfo(circle * cptr)
{
  printf("[%d, %d] \n"(cptr->cen).xpos, (cptr->cen).ypos);

  printf("raduis: %g \n\n", cptr->rad);
}



int main()
{
  circle c1={{1,2}, 3.5}; 중괄호를 써서 초기화할수있다.

  circle c2={24 ,3.9};  차례대로도 할수있다.

  ShowCircleInfo(&c1);
  ShowCircleInfo(&c2);
  

  return 0;
}



 #include <stdio.h>


union smart
{
  int A;
  short B;
  char C;
};

int main()
{
  union smart test;
  test.A = 0x12345678;   

  printf("%X \n", test.A);  메모리에 들어가는 순서 78/56/34/12
  printf("%X \n", test.B);
  printf("%X \n", test.C);

  test.B = 0xAAAA;
  test.C = 0xFF;

  printf("%X \n", test.A);
  printf("%X \n", test.B);
  printf("%X \n", test.C);

  return 0;
}




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

20140415 연결리스트  (0) 2014.04.15
20140414 atmega구조  (0) 2014.04.14
20140410 구조체 변수와 포인터  (0) 2014.04.10
20140409 구조체 효율높이기  (0) 2014.04.09
20140408 구조체  (0) 2014.04.08
by 날라차숑 2014. 4. 11. 16:49