结 构 体

一、结构体

  数据类型——构造出来——一组数据 (不同数据类型)

  面向对象

二、语法

 1、定义

 

Struct 结构体名

{      成员表;      

成员函数;

}结构体变量表;

 

struct student{

     int num;

     string name;

     bool sex;

}a[62];

Struct 结构体名

{      成员表;      

成员函数;

};

结构体名 结构体变量表;

struct student{

     int num;

     string name;

     bool sex;

};

Student a[62];

*定义结构体时系统不分配内存,只有定义结构体变量时,才分配内存。

*结构体变量名与结构体名不能重复。

2、调用

成员调用

Student.name

成员函数调用

Student.f(x)

3、结构体变量的特点

  1、整体操作

   e.g  swap(a[j],a[j+1]);

更多推荐

Structure(结构体)