编程语言
首页 > 编程语言> > 结构体的各种使用方法详细讲解-c\c++

结构体的各种使用方法详细讲解-c\c++

作者:互联网

结构体

什么是结构体

为什么要使用结构体

结构体的定义

struct 结构名 {

成员类型 成员名;

成员类型 成员名;

};

实例

struct student {

int name[16]; //姓名

int age; //年龄

int tel; //电话

};

温馨提示

结构体里包含结构体

struct student {

int name[16];

int age;

int tel;

};

struct _class {

struct student xiaohua;

struct student heige;

struct student xiaohong;

};

结构体的初始化

struct student {

int name[16];

int age;

int tel;

};

struct student xiaohua = {"xiaohua",18,10086};

strcut student xiaohua ;

strcpy(xiaohua.name,"xiaohua");

xiaohua.age = 18;

xiaohua.tel = 10086;

初始化结构体中包含结构体

struct student {

int name [16];

int age;

int tel;;

};

struct _class {

struct student xiaohua;

struct student xiaohua;

struct student xiaohua;

};

 

struct _class n1= {

{"xiaohua",18,10086},

{"xiaohong",15,10086},

{"xiaohei",17,10086},

};

 

 

温馨提示

strcpy();在vs2019中需要添加_s,如:strcpy_s();

如果不添加会出现一下错误:

结构体的使用

 

 

 

 

 

标签:xiaohua,struct,student,int,数据类型,c++,详细,讲解,结构
来源: https://blog.csdn.net/weixin_46464021/article/details/106844920