1、示例代码
#include <iostream>
using namespace std;
struct st_girl
{
char name[21];
int score[2][3] = {11,12,13,21,22,23};
int age;
double weight;
char sex;
bool yz;
};
void func(st_girl* pst)
{
for (int ii = 0; ii < 2; ii++)
for (int jj = 0; jj < 3; jj++)
cout << "pst->score[" << ii << "][" << jj << "]=" << pst->score[ii][jj] << endl;
}
int main()
{
st_girl girl;
func(&girl);
}
#include <iostream>
using namespace std;
struct st_pet
{
char name[21];
char type[21];
};
struct st_girl
{
char name[21];
int age;
double weight;
char sex;
bool yz;
struct st_pet pet;
};
int main()
{
st_girl girl = { "西施",23,50.5,'X',true,{"宝宝","鸭子"} };
cout << "姓名:" << girl.name << "的宠物是一只" << girl.pet.type << ",名字叫" << girl.pet.name << "。" << endl;
girl = { "西瓜",25,51.5,'X',true,{"贝贝","天鹅"} };
cout << "姓名:" << girl.name << "的宠物是一只" << girl.pet.type << ",名字叫" << girl.pet.name << "。" << endl;
girl.pet = {"小白","狗"};
cout << "姓名:" << girl.name << "的宠物是一只" << girl.pet.type << ",名字叫" << girl.pet.name << "。" << endl;
}