레이드리안
2011. 8. 17. 16:26
구조체란?
사용자가 직접 자료형을 만들어서 사용하는것!
사용자가 직접 자료형을 만들어서 사용하는것!
사용법 ex)
struct 구조체{ struct my_spec{
자료형 변수 ; int tall;
}; int age;
char name[20];
};
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 → 구조체의 접근은 .(마침표)로 접근