48.5 연습문제: 좌표 구조체 정의하기
#include <stdio.h>
struct Point2D
{
int x;
int y;
};
int main(void)
{
struct Point2D p1;
p1.x = 10;
p1.y = 20;
printf("%d %d\n", p1.x, p1.y);
return 0;
}
48.6 연습문제: typedef로 좌표 구조체 정의하기
#include <stdio.h>
typedef struct _Point2D
{
int x;
int y;
} Point2D;
int main(void)
{
Point2D p1;
p1.x = 10;
p1.y = 20;
printf("%d %d\n", p1.x, p1.y);
return 0;
}
48.7 연습문제: 익명 구조체로 좌표 구조체 정의하기
#include <stdio.h>
typedef struct
{
int x;
int y;
} Point2D;
int main(void)
{
Point2D p1;
p1.x = 10;
p1.y = 20;
printf("%d %d\n", p1.x, p1.y);
return 0;
}
48.8 심사문제: 자동차 계기판 구조체 선언하기
#include <stdio.h>
struct Dashboard
{
int speed;
char fuel;
float mileage;
int engineTemp;
int rpm;
};
int main(void)
{
struct Dashboard car1 = { 80, 'F', 5821.442871f, 200, 1830 };
printf("Speed: %dkm/h\n", car1.speed);
printf("Fuel: %c\n", car1.fuel);
printf("Mileage: %fkm\n", car1.mileage);
printf("Engine temp: %d°C\n", car1.engineTemp);
printf("RPM: %d\n", car1.rpm);
return 0;
}
48.9 심사문제: 자동차 계기판 구조체 정의하기
#include <stdio.h>
typedef struct _Dashboard
{
int speed;
char fuel;
float mileage;
int engineTemp;
int rpm;
} Dashboard;
int main(void)
{
Dashboard car1;
car1.speed = 80;
car1.fuel = 'F';
car1.mileage = 5821.442871f;
car1.engineTemp = 200;
car1.rpm = 1830;
printf("Speed: %dkm/h\n", car1.speed);
printf("Fuel: %c\n", car1.fuel);
printf("Mileage: %fkm\n", car1.mileage);
printf("Engine temp: %d°C\n", car1.engineTemp);
printf("RPM: %d\n", car1.rpm);
return 0;
}