数据结构-C语言结构体的使用

结构体

解释:在使用C语言的时候,往往基本数据类型不能满足我们的需要,所以结构体这个概念也应运而生。结构体能够组合几种不同的基本数据类或其它数据类型形成一个新的数据类型。类似于面对对象中的类。


  •     声明

        关键字:struct

        形式:

struct node {
    int one;
    char two;
};    //;作为结构体的一部分 不能省去

  •     定义
             形式1:

struct node {
    int one;
    char two;
}Node;          

        形式2:

struct {
    int one;
    char two;
}Node;

        形式3:

struct node {
    int one;
    char two;
};
struct node Node;

  •     初始化
        形式1:

struct node {
    int one;
    char two;
}Node;    //默认初始化int型为0 char型为null    
        形式2:

struct node {
    int one;
    char two;
}Node={1, '2'};       
        形式3:

struct node {
    int one;
    char two;
};
struct node Node;
Node = {1, '2'};      

  • 结构体的引用
    整体引用:
struct node {
    int one;
    char two;
}Node={1, '2'};
struct node temp;
temp = Node;
      成员引用:
struct node {
    int one;
    char two;
}Node={1, '2'};
Node.one = 2;       

ps:如有错误,请指正,谢谢!






评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值