#include <stdlib.h>
#include <stdio.h>
#include <string.h>
struct student
{
char name[16];
int age;
char tel[12];
};
struct _class
{
student rock;
student martin;
student zsf;
};
int main(void)
{
struct student rock = { "***",38,"*********" };
printf("***的姓名: %s 年龄: %d 电话: %s\n", rock.name, rock.age, rock.tel);
student s2;
strcpy_s(s2.name, "***");
s2.age = 40;
s2.tel[0] = '\0';
printf("*** 的姓名: %s 年龄: %d 电话: %s\n", s2.name, s2.age, s2.tel);
_class c1 = { {"***",38,"********"},{"***",38,"***"},{"***",100,"*********"} };
printf("***同学的姓名: %s 年龄: %d 电话: %s\n", c1.martin.name, c1.martin.age, c1.martin.tel);
system("pause");
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
struct student
{
char name[16];
int age;
};
int main(void)
{
struct student s1, s2;
cout << "请输入第一个学生的姓名:" << endl;
cin >> s1.name;
cout << "请输入第一个学生的年龄:" << endl;
cin >> s1.age;
printf("第一个学生的姓名:%s 年龄: %d\n", s1.name, s1.age);
s2 = s1;
printf("第二个学生的姓名:%s 年龄: %d\n", s2.name, s2.age);
system("pause");
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
struct student
{
char name[16];
int age;
};
int main(void)
{
struct student s[2];
cout << "请输入第一个学生的姓名:" << endl;
cin >> s[0].name;
cout << "请输入第一个学生的年龄:" << endl;
cin >> s[0].age;
printf("第一个学生的姓名:%s 年龄: %d\n", s[0].name, s[0].age);
s[1] = s[0];
memcpy(&s[1], &s[0], sizeof(struct student));
printf("第二个学生的姓名:%s 年龄: %d\n", s[1].name, s[1].age);
system("pause");
return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
struct _friend
{
char name[32];
char sex;
int age;
};
int main5(void)
{
_friend girl = { "***", 'f', 18 };
_friend *my_girl = &girl;
printf("***的名字: %s, 性别: %s ,年龄: %d\n", girl.name, girl.sex == 'm' ? "男" : "女", girl.age);
printf("***的名字: %s, 性别: %s ,年龄: %d\n", (*my_girl).name, (*my_girl).sex == 'm' ? "男" : "女", (*my_girl).age);
printf("***的名字: %s, 性别: %s ,年龄: %d\n", my_girl->name, my_girl->sex == 'm' ? "男" : "女", my_girl->age);
system("pause");
return 0;
}