달력

72025  이전 다음

  • 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

구조체

C 2014. 3. 17. 02:18
구조체란?

사용자가 직접 자료형을 만들어서 사용하는것!


사용법                                       ex)
struct 구조체{                                            struct my_spec{
   자료형 변수 ;                                              int tall;
};                                                                 int  age;
                                                                   char name[20];
                                                                 };


위의 ex) 와같이 선언후
struct my_spec A;     → int 형 2개 char 형 한개를 묶어서 my_spec라는 자료형 A를 만듦.
A.tall = Value;



#include<stdio.h>
struct student{
   int id;
   char name[20];
   int kor,eng,math;
   char address[100];
};

void main()
{
   struct student ST= {201154321, "hong gil dong", 90,91,92,"서울 강남구 대치동"
};
   printf("ST구조체의 크기 : %d \n" sizeof(ST));
   printf("ST의 학번 : %d \n",ST.id);
   printf("ST의 이름: %s \n",ST.name);
   printf("ST의 성적(국,영,수):%d %d %d \n",ST.kor,ST.engm,ST.math);
   printft("ST의 주소:%s \n",ST.address);
}




*구조체를 정의하고 main에서 구조체 자료형(student)을 ST라는 변수로 선언.
  초기화는 구조체 타입에 정의한순서대로 (int, char,int,int,int,char)
printf문에서 ST.id  → 구조체의 접근은 .(마침표)로 접근

'C' 카테고리의 다른 글

구조체 와 포인터  (0) 2014.03.17
구조체 와 배열  (0) 2014.03.17
Call by Referance  (0) 2014.03.17
Call by Address  (0) 2014.03.17
Call by Value  (0) 2014.03.17
Posted by 레이드리안
|