📜  数据结构-结构体

📅  最后修改于: 2020-10-14 06:56:39             🧑  作者: Mango

结构体

结构是一种复合数据类型,它定义了一组变量列表,这些变量列表将以一个名称放置在内存块中。它允许使用指向结构的单个指针来访问不同的变量。

句法

struct structure_name 
{
    data_type member1;
    data_type member2;
    .
    .
    data_type memeber;
};

好处

  • 它可以保存不同数据类型的变量。
  • 我们可以创建包含不同类型属性的对象。
  • 它允许我们在程序之间重复使用数据布局。
  • 它用于实现其他数据结构,例如链表,堆栈,队列,树,图等。

程序

#include
#include
void main( )
{
struct employee
{
int id ;
float salary ;
int mobile ;
} ;
struct employee e1,e2,e3 ;
clrscr();
printf ("\nEnter ids, salary & mobile no. of 3 employee\n"
scanf ("%d %f %d", &e1.id, &e1.salary, &e1.mobile);
scanf ("%d%f %d", &e2.id, &e2.salary, &e2.mobile);
scanf ("%d %f %d", &e3.id, &e3.salary, &e3.mobile);
printf ("\n Entered Result ");
printf ("\n%d %f %d", e1.id, e1.salary, e1.mobile);
printf ("\n%d%f %d", e2.id, e2.salary, e2.mobile);
printf ("\n%d %f %d", e3.id, e3.salary, e3.mobile);
getch();
}