본문 바로가기
728x90
반응형
SMALL

개념125

chapter 17) 구조체를 변환하여 두 변수의 값 교환 #include struct vision{ double left, right; }; struct vision exchange(struct vision robot); int main(void){ struct vision robot; printf("vision input : "); scanf("%lf%lf", &(robot.left), &(robot.right)); robot = exchange(robot); printf("change vision : %.1lf %.1lf\n", robot.left, robot.right); return 0; } struct vision exchange(struct vision robot){ double temp; temp = robot.left; robot.left = r.. 2024. 9. 28.
chapter 17) 구조체 포인터의 사용 #include struct score{ int kor,eng,math; }; int main(void){ struct score yuni = {90,80,70}; struct score *ps = &yuni; printf("kor : %d\n", (*ps).kor); printf("eng : %d\n", ps -> eng); printf("math : %d\n", ps -> math); return 0; } ### 구조체 정의 - `struct score`는 세 과목의 점수를 정수형으로 저장하는 구조체입니다. 각 멤버 변수 `kor`, `eng`, `math`는 국어, 영어, 수학 점수를 나타냅니다. ### `main` 함수 - `struct score yuni = {90, 80, 70};`를 통해 `.. 2024. 9. 27.
chapter 17) 공동체를 사용한 학번과 학점 데이터 처리 #include union student{ int num; double grade; }; int main(void){ union student s1 = {315}; printf("class : %d\n", s1.num); s1.grade = 4.4; printf("class : %.1lf\n", s1.grade); printf("grade : %d\n", s1.num); return 0; } ### `union`의 특징과 사용 - `union student s1 = {315};`로 `union`을 초기화할 때, `num` 멤버에 315를 할당합니다. 이 시점에서 `s1`의 `num` 멤버만 유효한 값으로 설정됩니다. - `printf("class : %d\n", s1.num);`에서 `s1.num`의 값.. 2024. 9. 26.
chapter 17) typedef 를 사용한 자료형 재정의 #include struct student{ int num; double grade; }; typedef struct student Student; void print_data(Student *ps); int main(void){ Student s1 = {315, 4.2}; print_data(&s1); return 0; } void print_data(Student *ps){ printf("class : %d\n", ps -> num); printf("grade : %.1lf\n", ps -> grade); } ### 프로그램의 구성 - `struct student`: 학생의 정보를 나타내기 위한 구조체로, 정수형의 `num` (학번)과 실수형의 `grade` (성적) 두 개의 멤버 변수를 갖습니다. .. 2024. 9. 25.
728x90
반응형
LIST