zoukankan      html  css  js  c++  java
  • 指针变量输出结构体数组元素

    /*用指针变量输出结构体数组元素。*/

    #include <stdio.h>
    //定义一个结构体并同时进行初始化
    struct student{
        int num;
        char *name;
        char sex;
        int age;
    } stu[5] = {
        {20100290,"lihua",'F',18},
        {20100291,"liuxing",'M',19},
        {20100292,"huangke",'F',19},
        {20100295,"fengshou",'F',19},
        {20100296,"Wangming",'M',18}
    };
    
    int main(int argc, const char * argv[]) {
        
        int i;
        //定义一个指向结构体的指针
        struct student *ps;
        printf("学号		姓名		性别	年龄	
    ");
        
        /*用指针变量输出结构体数组元素。*/
        for(ps=stu;ps<stu+5;ps++)
            printf("%d	%-10s	%c	%d	
    ",ps->num,ps->name,ps->sex,ps->age);
        
        //华丽的分割线
        printf("---------------------------------
    ");
        
        /*用数组下标法输出结构体数组元素学号和年龄。*/
        for(i=0;i<5;i++)
            printf("%d	%-10s	%c	%d	
    ",stu[i].num,stu[i].name,stu[i].sex,stu[i].age);
        
        return 0;
    }
  • 相关阅读:
    Android AdapterView View的复用机制 分析
    go12---interface
    go11---方法method
    go10---struct
    go09---defer
    go8---函数function
    go7---map
    go6---slice切片
    go5--数组
    go4--break,continue + 标签
  • 原文地址:https://www.cnblogs.com/wm-0818/p/5276232.html
Copyright © 2011-2022 走看看