zoukankan      html  css  js  c++  java
  • 结构体指针和数组理解

    (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
  • 相关阅读:
    bzoj 3779: 重组病毒【LCT+线段树维护dfs序】
    bzoj 4817: [Sdoi2017]树点涂色【树链剖分+LCT】
    bzoj 4818: [Sdoi2017]序列计数【容斥原理+dp+矩阵乘法】
    bzoj 1853: [Scoi2010]幸运数字&&2393: Cirno的完美算数教室【容斥原理】
    bzoj 3589: 动态树【树链剖分+容斥】
    bzoj 1042: [HAOI2008]硬币购物【容斥原理+dp】
    bzoj 4517: [Sdoi2016]排列计数【容斥原理+组合数学】
    好听的英文歌曲
    颜色色环
    颜色模式
  • 原文地址:https://www.cnblogs.com/sxmcACM/p/3463609.html
Copyright © 2011-2022 走看看