1 / 7

C 프로그래밍 언어

C 프로그래밍 언어. 7 장 . 편리한 구조체 정보통신공학부 박기현. 7.1 구조체란 ? (P270). main () {         char *name;     /* 이름을 보관 * /         int id;           /* 학번을 보관 * /         int grade;       /* 성적을 보관 * /         name = "Hong, Kil Dong";         id = 123;         grade = 90;

daisy
Download Presentation

C 프로그래밍 언어

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C 프로그래밍 언어 7장. 편리한 구조체 정보통신공학부 박기현

  2. 7.1 구조체란?(P270) main () {         char *name;     /* 이름을 보관 */         int id;           /* 학번을 보관 */         int grade;       /* 성적을 보관 */         name = "Hong, Kil Dong";         id = 123;         grade = 90;         printf ("%d[%s]: %d\n", id, name, grade); } (결과) 123[Hong, Kil Dong]: 90

  3. 7.2 선언과 초기화 – 선언 (P272) main () {         struct grade_t {                 char *name;                 int id;                 int grade;         };         struct grade_t data;         data.name = "Hong, Kil Dong";         data.id = 123;         data.grade = 90;         printf ("%d[%s]: %d\n", data.id, data.name, data.grade); } (결과) 123[Hong, Kil Dong]: 90

  4. 7.2 선언과 초기화 – 초기화 (P274) main () {         struct grade_t {                 char *name;                 int id;                 int grade;         };         struct grade_t data = {"Hong, Kil Dong", 123, 90};         printf ("%d[%s]: %d\n", data.id, data.name, data.grade); } (결과) 123[Hong, Kil Dong]: 90

  5. 7.2 선언과 초기화 – 예제 (P276) struct grade_t {         char *name;         int id;         int grade; }; out (struct grade_t in) {         printf ("%d[%s]: %d\n", in.id, in.name, in.grade); } main () {         struct grade_t data1 = {"Hong, Kil Dong", 123, 90};         struct grade_t data2;         data2.name = "Jang, Kil San";         data2.id = 124;         data2.grade = data1.grade;         out (data1);         out (data2); }

  6. 7.3 포인터의 활용 – 포인터 변수 (P278) struct grade_t {         char *name;         int id;         int grade; }; main () {         struct grade_t data;         struct grade_t *p = &data;         data.name = "Hong, Kil Dong";         p->id = 123;         p->grade = 90;         printf ("%d[%s]: %d\n", data.id, data.name, data.grade); } (결과) 123[Hong, Kil Dong]: 90

  7. 7.3 포인터의 활용 – malloc()(P280) struct grade_t {         char *name;         int id;         int grade; }; main () {         struct grade_t *p;         p = (struct grade_t *)malloc (sizeof (struct grade_t));         p->name = "Hong, Kil Dong";         p->id = 123;         p->grade = 90;         printf ("%d[%s]: %d\n", p->id, p->name, p->grade);         printf ("p = 0x%x\n", p); }

More Related