C,C++
C,C++ : 구조체 만들기(struct)
디자이너 기즈모
2023. 7. 31. 18:17
main.cpp
#include <stdio.h>
int main1_1()
{
typedef struct { int x, y; } Point;
Point p;
p.x = 10;
p.y = 20;
printf("(%d, %d)\n", p.x, p.y);
return 0;
}
int main1_2()
{
struct { int x, y; } p;
p.x = 10;
p.y = 20;
printf("(%d, %d)\n", p.x, p.y);
return 0;
}
struct p {
private: //비공개
int x, y;
public: //공개
int getX() { return x; }
int getY() { return y; }
void setX(int _x) { x = _x; }
void setY(int _y) { y = _y; }
p() :x(0), y(0) { printf("시작\n"); }; //초기
~p() { printf("끝"); }//끝
};
int main1_3()
{
p p1;
p1.setX(500);
p1.setY(20);
printf("(%d, %d)\n", p1.getX(), p1.getY());
return 0;
}
int main()
{
main1_1();
main1_2();
main1_3();
return 0;
}