日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言结构体编程,[编程] C语言的结构体详解

發(fā)布時(shí)間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言结构体编程,[编程] C语言的结构体详解 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

結(jié)構(gòu)體

struct 結(jié)構(gòu)體名{}變量名;

結(jié)構(gòu)體變量:

struct person{

char *name;

int age;

float score;

} student;

成員的獲取和賦值

//Members of the acquisition and assignment

student.name="taoshihan";

student.age=30;

student.score=100;

printf("name=%s \n",student.name);

C語言結(jié)構(gòu)體數(shù)組

struct stu{

char *name;

int age;

float score;

} classes[5];

遍歷結(jié)構(gòu)體數(shù)組

struct people{

char *name;

int age;

float score;

} d[]={

{"taoshihan",20,100},

{"lisi",30,90}

};

int len=sizeof(d)/sizeof(d[0]);

printf("d length=%d \n",len);

for(int i=0;i

printf("loop...%s,%d,%.1f \n",d[i].name,d[i].age,d[i].score);

}

C語言結(jié)構(gòu)體和指針

struct 結(jié)構(gòu)體名*變量名;

struct person1{

char *name;

int age;

float score;

} a={"taoshihan",20,100},*b=&a;

struct person1 *c=&a;

獲取結(jié)構(gòu)體成員

printf("b.name=%s \n",(*b).name);

printf("c.name=%s \n",c->name);

完整代碼:

#include

intmain(){

printf("hello world");//Structure variables

structperson{char *name;intage;floatscore;

} student;//Members of the acquisition and assignment

student.name="taoshihan";

student.age=30;

student.score=100;

printf("name=%s \n",student.name);//c struct array

structstu{char *name;intage;floatscore;

} classes[5];structstu1{char *name;intage;floatscore;

} classes1[2]={

{"taoshihan",20,100.00},

{"lisi",20,90}

};structstu2{char *name;intage;floatscore;

} classes3[]={

{"taoshihan",20,100}

};

printf("%s \n",classes1[1].name);//Traverse the array of structures

structpeople{"chaper5.c" 71L, 1199C 1,1Top//Traverse the array of structures

structpeople{char *name;intage;floatscore;

} d[]={

{"taoshihan",20,100},

{"lisi",30,90}

};int len=sizeof(d)/sizeof(d[0]);

printf("d length=%d \n",len);for(int i=0;i

printf("loop...%s,%d,%.1f \n",d[i].name,d[i].age,d[i].score);

}//C language structure and pointer

structperson1{char *name;intage;floatscore;

} a={"taoshihan",20,100},*b=&a;struct person1 *c=&a;//Get the structure member

printf("b.name=%s \n",(*b).name);

printf("c.name=%s \n",c->name);

}

總結(jié)

以上是生活随笔為你收集整理的c语言结构体编程,[编程] C语言的结构体详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。