#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;
class stu{
private:
int age;
char sex;
float high;
public:
int get_age();
char get_sex();
float get_high();
void set_info(int age, char sex = 'w', float high = 160);
};
int stu::get_age(){
return age;
}
char stu::get_sex(){
return sex;
}
float stu::get_high(){
return high;
}
void stu::set_info(int a, char b, float c){
age = a;
sex = b;
high = c;
}
int main()
{
stu s;
s.set_info(24);
cout << s.get_age() << endl;
cout << s.get_sex() << endl;
cout << s.get_high() << endl;
s.set_info(30, 'm', 175.5);
cout << s.get_age() << endl;
cout << s.get_sex() << endl;
cout << s.get_high() << endl;
return 0;
}
1、
struct data{
char t1;
char t2;
unsigned short t3;
unsigned long t4;
}; //32位:12字节,64位:16字节
2、
struct data{
char t1;
int t2;
short t3;
}; //12字节
3、
struct s1{
char c1;
int i;
char c2;
}; //12字节
4、
//2字节对齐
struct s2{
char c1;
int i;
char c2;
}; //8字节
5、
typedef struct Test
{
short a;
struct
{
int b;
double c;
char d;
};
int e;
}Test; //8字节
6、
typedef struct Test
{
short a;
struct
{
int b;
double c[10];
char d;
};
int e;
}Test; //8字节
7、
struct C{
char b;
int a;
short c;
}; //12字节
8、
struct C {
char a;
char b[3];
char c;
}; //5字节
9、
typedef struct
{
int b;
char a;
long e;
char c;
float d;
double t;
}node; //32位:28字节,64位:32字节