728x90
구조체(Structure)
: 서로 다른 자료형의 데이터를 하나의 그룹으로 묶은 자료형
구조체의 선언
struct student{
char name[20+1]; //+1은 null문자를 추가해준 것.
int num;
float grade;
}
구조체의 초기화
방법 1) 구조체의 초기화 | 방법 2) 값 설정 |
struct student student_lee = {"lee",2004153648, 92.5}; | struct student student_lee={0}; strcpy(student_lee.name,"lee"); student_lee.year = 2004153648, student_lee.grade = 92.5; |
구조체 변수의 복사(값 복사)
struct student lee_src = {"lee",2004153648,92.5};
struct student lee_dest ={0,};
lee_dust = lee_src;
// 29byte로 동일하게 복사가 됨.
typedef : 새로운 구조체를 하나의 데이터 타입으로 재정의
typedef struct student_type{
char name[20+1];
int num;
float grade;
} student;
student lee_src = {"lee",2004153648, 92.5};
반응형
'Study Log > 자료구조' 카테고리의 다른 글
[자료구조] 포인터를 이용한 동적 메모리 할당 (0) | 2021.04.25 |
---|---|
[자료구조] 포인터의 의미와 사용법(참조연산자 *, 주소연산자 &) (0) | 2021.04.25 |
[자료구조] C프로그래밍 기법(2) - 배열 (0) | 2021.04.23 |
[자료구조] C프로그래밍 기법(1) - C의 단순 자료형 (0) | 2021.04.23 |
[자료구조] 알고리즘의 의미와 특성 (0) | 2021.04.23 |