Definition and basic use of C++ structure

 **结构体**是一个由程序员定义的数据类型,可以容纳许多不同的数据值。在定义一个新的结构体之后它与Int,char,float,double相同为一种数据类型,只是结构体中可能包含多种不同的数据类型可以有数组,整型,浮点型等。
  关于定义一个新的结构体,这里要用到关键字  **struct**
  定义一个结构体的形式为:
  struct  标识符
         类型 成员1;
         类型 成员2;
         类型 成员3;
     };

Example: define a new structure contact, which contains integer id, character array name and phone

struct contact
{
    
    
   int id;
   char name[16];
   char phone[16];
};

About initialization structure

After defining a new structure contact, use the example given above to demonstrate:

contact a=123456"Jhon","123456789";

Regarding access to the id in structure a, you can access it like this:

a.id=123456;

Guess you like

Origin blog.csdn.net/weixin_45688342/article/details/104490002