Ex-멤버변수로 구조체 변수를 사용하는 중첩구조체

CODEDRAGON Development/C, C++

반응형

   

멤버변수로 구조체 변수를 사용하는 중첩구조체

중첩구조체는 구조체 내에 구조체가 포함되어 있는 구조

   

   

메모리 도식도

   

   

소스코드

   

#include <stdio.h>

struct score{
        double math;
        double english;
        double korean;
        double total;
};

struct student{
        int no;
        struct score ss;                //
구조체 변수 ss 구조체 student 멤버 변수로 사용(중첩 구조체)
};

int main(void){
        struct student stu;

        stu.no=1234567;
        stu.ss.math=90;
        stu.ss.english=80;
        stu.ss.korean=70;
        stu.ss.total=stu.ss.math+stu.ss.english+stu.ss.korean;

        printf("
학번: %d \n", stu.no);
        printf("
총점: %lf \n", stu.ss.total);

        return 0;
}


   

   

출력결과

 

반응형

'Development > C, C++' 카테고리의 다른 글

Error-입력버퍼 비우는 방법  (0) 2017.04.14
Ex-중첩구조체 초기화  (0) 2017.04.07
Ex-구조체 변수간 산술연산 불가능  (0) 2017.03.25
Ex - 구조체 변수들간 복사  (0) 2017.03.20
Ex-구조체 변수의 초기화  (0) 2017.03.14