일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 패킹
- 함수
- 포인터
- C언어
- 동적할당
- 자료형
- phpmyadmin
- 42서울
- float
- list
- libft
- 42cursus
- ft_server
- 42
- jupyter 단축키
- Class
- 2차원배열
- else if
- C++
- Double
- nginx
- iF
- for
- docker
- 구조체
- While
- cout
- 42Seoul
- python
- vs코드 단축키
- Today
- Total
목록구조체 (4)
Developer

구조체 변수 선언 #include #include using namespace std; struct student{ string name; int id; int age; string phonenumber; }; int main(){ student a1={"김모군",123456,20,"010xxxxxxxx"}; cout

CPU는 비트에 따라서 메모리 접근 단위가 다르다. 32비트의 컴퓨터는 32비트 단위로, 64비트의 컴퓨터는 64비트 단위로 접근한다. 대부분의 C언어 컴파일러는 CPU가 효율적으로 메모리에 접근할 수 있도록 구조체를 정렬해준다. 그럼 구조체 정렬이 무엇인지 알아보자. 구조체 정렬 #include typedef struct { //구조체 정의 char a; int b; }some; int main() { some c; //구조체 변수 선언 printf("멤버변수 a의 크기 :%d Byte\n", sizeof(c.a)); printf("멤버변수 b의 크기 :%d Byte\n", sizeof(c.b)); printf("구조체 변수 c의 크기 :%d Byte\n", sizeof(c)); return 0; ..

구조체도 다른 자료형과 같이 포인터, 배열을 사용할 수 있다. 구조체 포인터 #include #include typedef struct Student{ char name[30]; //이름 char phone_number[30]; //전화번호 int student_id; //학번 }Student; int main(){ Student s={"김모군","010-xxxx-xxxx",123456}; Student *sp; sp=&s; printf("-> 사용\n"); printf("%s\n",sp->name); printf("%s\n",sp->phone_number); printf("%d\n",sp->student_id); printf("\n역참조 사용\n"); printf("%s\n",(*sp).name); p..

구조체란 서로 다른 자료형의 여러 변수들을 하나의 묶음으로 사용할 수 있게 해준다. 기본 자료형을 조합해서 새로운 자료형을 만든다고 생각하면 된다.학생의 정보를 관리하기 위해 구조체를 사용해 보자. 정보 항목은 이름, 전화번호, 학번 3가지만 하겠다. #include #include struct Student{ char name[30]; //이름 char phone_number[30]; //전화번호 int student_id; //학번 }; int main(){ struct Student s; strcpy(s.name,"김모군"); strcpy(s.phone_number,"010-xxxx-xxxx"); s.student_id=123456; printf("%s\n",s.name); printf("%s\n"..