设为首页 加入收藏

TOP

C语言开发教程_结构体、结构体指针、tyepdef、union、enum(二)
2017-11-16 08:42:09 】 浏览:412
Tags:语言 开发 教程 结构 指针 tyepdef union enum
10; int i = 0; Node * list; list = (Node *)malloc(sizeof(struct Node)); list->data = 0; list->next = NULL; for (i = 0; i < num; i++) { enqueNode(list, i+1); } while (list->next != NULL) { printf("%d \n", list->data); list = list->next; } system("pause"); return 0; }

5. typedef 指令

//就是别名
//java 代理
//并没有创建新的数据类型,只是给现有类型创建了别名

typedef int _in;
typedef char * string;

typedef int(*PFI)(char *, char *);

typedef Tnode * Treeptr;
typedef struct Tnode {
    char *word;
    int count;

    /*Tnode * left;
    Tnode * right;*/
    Treeptr left;
    Treeptr right;
} BinaryTreeNode;

int fun(char *, char *) {
    return 0;
}
int main() {
    _in a = 20;
    printf("%d\n", a);

    string str;
    str = "hello world";

    PFI fp;
    fp = fun;

    char * ch;
    ch = "hello world";

    BinaryTreeNode* node;
    node = (BinaryTreeNode *) malloc(sizeof(BinaryTreeNode));

    system("pause");
    return 0;
}

6. 公用体 ,枚举

//union
//将不同的数据类型的数据放到同一段内存里面。
//占用的内存大小是 数据类型里面占用最大的那个内存大小
union MyUnion
{
    int a;
    char b;
    float c;
};

int main() {
    MyUnion unio;

    unio.a = 10;
    unio.b = 'a';
    unio.c = 1.2f;
    printf("a: %#x, b: %#x, c: %#x\n", &unio.a, &unio.b, &unio.c);
    // 只能取到 最近赋值的变量
    printf("a: %d, b: %c, c: %f\n", unio.a, unio.b, unio.c);

    system("pause");
    return 0;
}

enum {
    monday = 10,
            saturday,  、、
    sunday,
};
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C语言实现冒泡排序 下一篇C语言代码筛选求素数和普通求法

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目