C言語の構造体のメモ

構造をエイリアスにtypedefを

それは、後に使用を容易にするために、従来構造の匿名または構成することができます。

#include<stdio.h>
typedef struct{ //匿名结构
    float tank_capacity;
    int tank_psi;
    const char *suit_material;
} equipment;   //结构的别名

typedef struct scuba{ //结构名
    const char *name;
    equipment kit;
} diver;

void badge(diver d){
    //使用“点表示法”访问结构的值,不能使用下标
    printf("Name:%s Tank:%2.2f(%i) Suite:%s\n",d.name,d.kit.tank_capacity,d.kit.tank_psi,d.kit.suit_material);

};

int main(){
    diver randy = {"Randy",{5.5,3500,"Neoprene"}};
    badge(randy);
    return 0;
}

要素を構造化する割り当て

C言語で、構造が割り当てられると、コンピュータ・コピー構造体の値。ポインタを構築する必要があります

typedef sturct{
  const char *name;
  int age;
} turtle;

turtle t={"lisa",12}

(* T).ageと異なる意味t.age
t.ageこのメモリセルの内容を表し等しい*(t.age)。
一般的に読みやすい執筆(* T).age別の形式
(* T).age T - ==>年齢
"年齢フィールド構造で点t" T->年齢手段を

おすすめ

転載: www.cnblogs.com/c-x-a/p/11527638.html