본문 바로가기
코딩/C++

구조체

by sonysame 2024. 3. 6.
#include <iostream>

using namespace std;

struct Person {
	double height; 
	float weight;
	int age;
	string name;

	void print() {
		cout << height << " " << weight << " " << age << " " << name;
		cout << endl;
	}
};

struct Employee {
	short id; //2
	int age; //4
	double wage; //8
};
Person getMe() {
	Person me{ 2.0, 100.0, 20, "Jack Jack" };
	return me;
}
void printPerson(Person ps) {
	cout << ps.height << " " << ps.weight << " " << ps.age << " " << ps.name;
	cout << endl;

}

int main() {
	Person me{ 2.0, 100.0, 20, "Jack Jack" };
	Person me_from_func = getMe();
	Person mom;
	Person dad;
	printPerson(me);
	me_from_func.print();

	cout << sizeof(Employee) << endl; //padding 들어감
}

'코딩 > C++' 카테고리의 다른 글

문자열 const char *  (0) 2024.03.08
포인터  (0) 2024.03.07
자료형 별칭(typedef, using)  (0) 2024.03.05
열거형(enum)  (0) 2024.03.05
입력받는 법  (0) 2024.02.22