📅  最后修改于: 2023-12-03 15:00:12.865000             🧑  作者: Mango
本程序使用C语言中的Structure结构体数据类型,实现打印员工详细信息功能。结构体是由不同类型的数据组成的一个自定义数据类型,通过它可以方便地存储和访问多个相关的数据。
struct Employee {
char name[20];
char gender[6];
int age;
char position[20];
int work_years;
char phone[12];
};
int main() {
struct Employee emp = {"Tom", "Male", 28, "Engineer", 5, "13912345678"};
...
}
printf("Name: %s\n", emp.name);
printf("Gender: %s\n", emp.gender);
printf("Age: %d\n", emp.age);
printf("Position: %s\n", emp.position);
printf("Work years: %d\n", emp.work_years);
printf("Phone: %s\n", emp.phone);
#include <stdio.h>
struct Employee {
char name[20];
char gender[6];
int age;
char position[20];
int work_years;
char phone[12];
};
int main() {
struct Employee emp = {"Tom", "Male", 28, "Engineer", 5, "13912345678"};
printf("Name: %s\n", emp.name);
printf("Gender: %s\n", emp.gender);
printf("Age: %d\n", emp.age);
printf("Position: %s\n", emp.position);
printf("Work years: %d\n", emp.work_years);
printf("Phone: %s\n", emp.phone);
return 0;
}
Name: Tom
Gender: Male
Age: 28
Position: Engineer
Work years: 5
Phone: 13912345678