结构体指针和数组理解
生活随笔
收集整理的這篇文章主要介紹了
结构体指针和数组理解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
(1)第一個
1 # include<iostream> 2 using namespace std; 3 struct student 4 { 5 int num; 6 char name[12]; 7 char sex; 8 int age; 9 }//stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 10 *st; 11 struct student stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 12 int main() 13 { 14 //struct student *st; 15 16 for(st = stu; st < stu+3; st++) 17 { 18 cout<<(*st).num<<" "<<(*st).name<<" "<<(*st).sex<<" "<<(*st).age<<endl; 19 20 } 21 cout<<"------------------------------------------------"<<endl; 22 for(st = stu; st < stu+3; st++) 23 { 24 cout<<st->num<<" "<<st->name<<" "<<st->sex<<" "<<st->age<<endl; 25 } 26 27 } View Code(2)第二個
1 # include<iostream> 2 using namespace std; 3 struct student 4 { 5 int num; 6 char name[12]; 7 char sex; 8 int age; 9 }//stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 10 ; 11 struct student stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 12 int main() 13 { 14 struct student *st; 15 16 for(st = stu; st < stu+3; st++) 17 { 18 cout<<(*st).num<<" "<<(*st).name<<" "<<(*st).sex<<" "<<(*st).age<<endl; 19 20 } 21 cout<<"------------------------------------------------"<<endl; 22 for(st = stu; st < stu+3; st++) 23 { 24 cout<<st->num<<" "<<st->name<<" "<<st->sex<<" "<<st->age<<endl; 25 } 26 27 } View Code(3)第三個
1 # include<iostream> 2 using namespace std; 3 struct student 4 { 5 int num; 6 char name[12]; 7 char sex; 8 int age; 9 }stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 10 11 //struct student stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 12 int main() 13 { 14 struct student *st; 15 16 for(st = stu; st < stu+3; st++) 17 { 18 cout<<(*st).num<<" "<<(*st).name<<" "<<(*st).sex<<" "<<(*st).age<<endl; 19 20 } 21 cout<<"------------------------------------------------"<<endl; 22 for(st = stu; st < stu+3; st++) 23 { 24 cout<<st->num<<" "<<st->name<<" "<<st->sex<<" "<<st->age<<endl; 25 } 26 27 } View Code(4)第四個(注意看typedef)
1 # include<iostream> 2 using namespace std; 3 typedef struct student 4 { 5 int num; 6 char name[12]; 7 char sex; 8 int age; 9 }//stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 10 stt; 11 stt stu[3] = {{1,"miao",'M',19},{2,"chuang",'F',23},{3,"hello",'M',24}}; 12 int main() 13 { 14 stt *st; 15 16 for(st = stu; st < stu+3; st++) 17 { 18 cout<<(*st).num<<" "<<(*st).name<<" "<<(*st).sex<<" "<<(*st).age<<endl; 19 20 } 21 cout<<"------------------------------------------------"<<endl; 22 for(st = stu; st < stu+3; st++) 23 { 24 cout<<st->num<<" "<<st->name<<" "<<st->sex<<" "<<st->age<<endl; 25 } 26 27 } View Code?
轉載于:https://www.cnblogs.com/sxmcACM/p/3463609.html
總結
以上是生活随笔為你收集整理的结构体指针和数组理解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu在系统启动logo过后无法进
- 下一篇: vsftpd下错误之:500 OOPS