카테고리 없음

C언어 코딩도장 49.9 구조체 포인터에 구조체 변수의 주소 할당하기

240 • 사공이 2020. 8. 21. 18:07

문제 : 3차원 좌표 구조체 Point3D가 정의되어 있습니다. 다음 소스 코드를 완성하여 좌표 정보가 출력되게 만드세요.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
 
struct Point3D {
    float x;
    float y;
    float z;
};
 
int main()
{
    struct Point3D p1 = { 10.0f, 20.0f, 30.0f };
    struct Point3D *ptr;
 
    ptr = &p1;
 
    printf("%f %f %f\n", ptr->x, ptr->y, ptr->z);
 
    return 0;
}
cs