C语言结构体2

#include <stdio.h>
#define LEN 20

struct names{
    char first[LEN];
    char last[LEN];
};

struct guy{
    struct names handle;
    char favfood[LEN];
    char job[LEN];
    float income;
};

struct people{
    struct names handle;
    char favfood[LEN];
    char job[LEN];
    float income;
    int (*showinfo2)(struct people *him);
};

int show2(struct people *him){
    // 用点还是->,是由这个前面是什么东西决定。如果它是指针,就用->,否则就用.
    printf("%s, %s, %s, %s, %.2f \n", him->handle.first, him->handle.last, him->favfood, him->job, him->income);
    // printf("%s, %s, %2f",  him->favfood, him->job, him->income);
    // printf(" %s, %s, %f", him.favfood, him.job, him.income);
}

int show(struct guy *him){
    // 用点还是->,是由这个前面是什么东西决定。如果它是指针,就用->,否则就用.
    printf("%s, %s, %s, %s, %.2f \n", him->handle.first, him->handle.last, him->favfood, him->job, him->income);
    // printf("%s, %s, %2f",  him->favfood, him->job, him->income);
    // printf(" %s, %s, %f", him.favfood, him.job, him.income);
}

int main(void){
    struct guy fellow[2]={
        {
            {"Even" , "Villard"},
            "tomato",
            "testing",
            12000.22
        },
        {
            {"first" , "second"},
            "no"
            "coding",
            120.12
        },
    };

    struct guy *him;
    printf("address %p, %p \n", &fellow[0], &fellow[1]);
    him = &fellow[0];
    show(him);
    him++;
    show(him);

    struct people pp={
        .handle = {"p1", "p2"},
        .favfood = "nothing",
        .job = "dance",
        .income = 3333300.22
    };
    show(&pp);
    pp.showinfo2 = show2;
    pp.showinfo2(&pp);
    
    return 0;
}

相关推荐

  1. C语言结构2

    2024-01-14 00:18:05       64 阅读
  2. c语言-结构

    2024-01-14 00:18:05       66 阅读
  3. 结构(C语言)

    2024-01-14 00:18:05       57 阅读
  4. C语言结构

    2024-01-14 00:18:05       50 阅读
  5. C语言----结构

    2024-01-14 00:18:05       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-14 00:18:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-14 00:18:05       106 阅读
  3. 在Django里面运行非项目文件

    2024-01-14 00:18:05       87 阅读
  4. Python语言-面向对象

    2024-01-14 00:18:05       96 阅读

热门阅读

  1. 文件包含漏洞原理以及修复方法

    2024-01-14 00:18:05       69 阅读
  2. 11.【TypeScript 教程】函数(Function)

    2024-01-14 00:18:05       55 阅读
  3. Unity-游戏与帧

    2024-01-14 00:18:05       62 阅读
  4. 编程探秘:Python深渊之旅-----算法的舞蹈(二)

    2024-01-14 00:18:05       67 阅读
  5. Uber,Meta随着股票下滑而减少招聘

    2024-01-14 00:18:05       68 阅读
  6. getopt()函数详细解释!保证看明白

    2024-01-14 00:18:05       55 阅读