C语言在本地范围内的结构是什么?
结构是不同数据类型变量的集合,以单个名称分组在一起。
结构声明的一般形式
结构声明如下-
struct tagname{
datatype member1;
datatype member2;
datatype member n;
};在这里,struct是关键字。
标记名指定结构的名称。
member1,member2指定组成结构的数据项。
示例
以下示例显示了在本地范围内该结构的用法。
struct book{
int pages;
char author [30];
float price;
};范例程序
以下程序显示了本地范围内的用法结构。
#include<stdio.h>
struct{
char name[20];
int age;
int salary;
char add[30];
}emp1,emp2;
int manager(){
struct{ //当地范围的结构
char name[20];
int age;
int salary;
char add[50];
}manager ;
manager.age=27;
if(manager.age>30)
manager.salary=650000;
else
manager.salary=550000;
return manager.salary;
}
int main(){
printf("输入emp1的名称:");
//gets(emp1.name);
scanf("%s",emp1.name);
printf("\nenter the add of emp1:");
scanf("%s",emp1.add);
printf("\nenter the salary of emp1:");
scanf("%d",&emp1.salary);
printf("\nenter the name of emp2:");
//gets(emp2.name);
scanf("%s",emp2.name);
printf("\nenter the add of emp2:");
scanf("%s",emp2.add);
printf("\nenter the salary of emp2:");
scanf("%d",&emp2.salary);
printf("\nemp1 salary is %d",emp1.salary);
printf("\nemp2 salary is %d",emp2.salary);
printf("\nmanager salary is %d",manager());
return 0;
}输出结果执行以上程序后,将产生以下结果-
输入emp1的名称:Bob enter the add of emp1:Hyderabad enter the salary of emp1:500000 enter the name of emp2:Hari enter the add of emp2:Chennai enter the salary of emp2:450000 emp1 salary is 500000 emp2 salary is 450000 manager salary is 550000
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短