zoukankan      html  css  js  c++  java
  • C语言

    c语言中可以选择的数据类型太少了。
    Java中有一些高级的数据结构。
    结构中能够存放基本的数据类型以及其他的结构。
    结构定义,一般放在程序的开头部分。
    一般放在include之后。

    #include <stdio.h>
    #include <string.h>
    struct Hero {
        int id;
        char name[50]; // 英雄名称
        int level;     // 英雄的等级
        int hp;        // 英雄的血量
        int mp;        // 英雄的魔法值
        char skill[50];  // 英雄的技能
    
    };
    int main()
    {
        // 使用结构体
        struct Hero hero1;
        hero1.id = 1;
        strcpy(hero1.name ,"张三");
        hero1.level = 5;
        hero1.hp = 500;
        hero1.mp = 100;
        strcpy(hero1.skill,"大保健");
        printf("%d	%s	%d	%d	%s
    ",hero1.id,hero1.name,hero1.level,hero1.hp,hero1.skill);
    
        return 0;
    }
    
    
    #include <stdio.h>
    #include <string.h>
    typedef struct Hero {
        int id;
        char name[50]; // 英雄名称
        int level;     // 英雄的等级
        int hp;        // 英雄的血量
        int mp;        // 英雄的魔法值
        char skill[50];  // 英雄的技能
    
    } Hero1;
    int main()
    {
        // 使用结构体
        Hero1 hero1;
        hero1.id = 1;
        strcpy(hero1.name ,"张三");
        hero1.level = 5;
        hero1.hp = 500;
        hero1.mp = 100;
        strcpy(hero1.skill,"大保健");
        printf("%d	%s	%d	%d	%s
    ",hero1.id,hero1.name,hero1.level,hero1.hp,hero1.skill);
    
        return 0;
    }
    

    typeof struct 之后,可以在下面方便的使用,不需要再加上struct关键字了。

  • 相关阅读:
    函数式编程
    scala 有 + 运算符吗?
    使用 Idea 打 scala程序的 jar 包
    相见恨晚的 scala
    半夜思考,为什么 String 具有不变性
    我的常用
    DataTable学习笔记
    Js 操作cookie
    嵌套的 ajax 请求
    Jquery插件收集【m了慢慢学】
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/8289280.html
Copyright © 2011-2022 走看看