zoukankan      html  css  js  c++  java
  • 对结构体数组的初步学习

    开始

    [作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ]

    [root@localhost test]# cat teststr.c
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
    
        struct person
        {
           char name[8];
           int age;
           char sex[4];
           char depart[20];
        };
    
        struct person student;
    
        struct person class[]=
        {
           {
              "Tom",
              23,
              "man",
              "product"
           },
    
           {
              "Jack",
              25,
              "wom",
              "R&D" 
           }
        };
    
        fprintf(stderr,"first is: %s\n", class[0].name);
        return 0;
    }
    [root@localhost test]# 

    运行结果:

    [root@localhost test]# gcc -o teststr teststr.c
    [root@localhost test]# ./teststr
    first is: Tom

    [作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ]

    并且,我们可以发现,不完全匹配也是可以的:

    [root@localhost test]# cat teststr.c
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
    
        struct person
        {
           char name[8];
           int age;
           char sex[4];
           char depart[20];
        };
    
        struct person student;
    
        struct person class[]=
        {
           {
              "Tom",
              23,
              "man"
           },
    
           {
              "Jack",
              25,
              "wom"
           }
        };
    
        fprintf(stderr,"first is: %s\n", class[0].name);
        return 0;
    }
    [root@localhost test]# gcc -o teststr teststr.c
    [root@localhost test]# ./teststr
    first is: Tom
    [root@localhost test]# 

    结束

  • 相关阅读:
    HDU5914
    HDU1087(dp)
    HDU1711(KMP)
    HDU1251(字典树)
    HDU3068(Manacher算法)
    POJ2187(旋转卡壳)
    HDU1392(凸包)
    CodeForces 722B
    CodeForces 722A
    CodeForces 721B
  • 原文地址:https://www.cnblogs.com/gaojian/p/2750628.html
Copyright © 2011-2022 走看看