C言語-構造とポインター学習

#include <stdio.h> 
#include <string.h> 
struct book //構造体タイプを定義
{ 
    charname [20]; 
    short price; 
    char author [20]; 
}; 
int main()
{ 
    struct book b1 = {" Cプログラミング言語 "、55、" TanHaoqiang "};構造体タイプを使用して構造体変数structbook 
    * p =&b1;構造体タイプを使用して構造体ポインターを定義し、構造体変数
    strcpy(b1。 name、 "C ++"); String Copy ----タイトルを修正strcpyprintf  
    ( "title:%s \ n"、p- > name);ポインタ->メンバー
    printf( "author:%s \ n"、 p- >作成者); 
    printf( "price:%d \ n"、b1.price);構造体。メンバー
}

ポインタ変数はアドレスを格納でき、*は間接参照演算子です。複雑な変数の定義には、構造体の参加が必要です。

おすすめ

転載: blog.51cto.com/15126924/2657659