코딩/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 들어감
}