码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • C Primer Plus(6) 中文版 第14章 结构和其他数据形式 14.5 嵌套结构


    14.5 嵌套结构
    有时,在一个结构中包含另一个结构(即嵌套结构)很方便。
    程序清单14.3 friend.c程序
    // friend.c -- example of a nested structure
    #include
    #define LEN 20
    const char * msgs[5] =
    {
        "    Thank you for the wonderful evening, ",
        "You certainly prove that a ",
        "is a special kind of guy. We must get together",
        "over a delicious ",
        " and have a few laughs"
    };

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

    struct guy {                       // second structure
        struct names handle;           // nested structure
        char favfood[LEN];
        char job[LEN];
        float income;
    };

    int main(void)
    {
        struct guy fellow = {   // initialize a variable
            { "Ewen", "Villard" },
            "grilled salmon",
            "personality coach",
            68112.00
        };
        
        printf("Dear %s, \n\n", fellow.handle.first);
        printf("%s%s.\n", msgs[0], fellow.handle.first);
        printf("%s%s\n", msgs[1], fellow.job);
        printf("%s\n", msgs[2]);
        printf("%s%s%s", msgs[3], fellow.favfood, msgs[4]);
        if (fellow.income > 150000.0)
            puts("!!");
        else if (fellow.income > 75000.0)
            puts("!");
        else
            puts(".");
        printf("\n%40s%s\n", " ", "See you soon,");
        printf("%40s%s\n", " ", "Shalala");
        
        return 0;
    } 

    /* 输出:

    */

    注意如何在结构中创建嵌套结构。和声明int类型一样,进行简单的声明:
    struct names handle;
    其次,诸如如何访问嵌套结构的成员,这需要使用两次点运算符:
    fellow.handle.first;
    .运算符的结合性是从左往右的。 

  • 相关阅读:
    Ipa Guard软件介绍:启动界面和功能模块全解析,保护你的iOS应用源码
    sqli-labs(less-11)
    TCP/IP网络参考模型
    JS类的继承和实现原理详解
    市场周刊杂志市场周刊杂志社市场周刊编辑部2022年第6期目录
    Covariance Estimators协方差估计大比拼:性能、应用场景和可视化对比总结
    Flask像Jenkins一样构建自动化测试任务
    RuntimeError: cuDNN error: CUDNN_STATUS_INTERNAL_ERROR
    一种基于局部适应度景观的进化规划的混合策略
    算法27:最长公共子序列——样本模型(4)
  • 原文地址:https://blog.csdn.net/weixin_40186813/article/details/126502451
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号