1. 程式人生 > >(c語言版)一個完整的程式,實現隨機生成20個元素的連結串列,快速查詢中間結點的值並顯示

(c語言版)一個完整的程式,實現隨機生成20個元素的連結串列,快速查詢中間結點的值並顯示

一、分清struct 與typedef struct

方法1:

#include <stdio.h>
typedef struct{
    int a;
    int b;
}test; //使用typedef 將test定義為一個結構體型別,這樣定義後
        //test相當於int,char等這樣變成了一種變數型別。

int main()
{
    test t;//定義一個“test”結構體型別的變數t
    t.a = 1;
    t.b = 2;

    printf("%d",t.a);
    return 0;   
}
方法2:
#include <stdio.h>
struct test{
    int a;
    int b;
};    //這裡相當於定義了一個結構體,這個結構體的名字叫test,因為沒有使用前面的typedef,因此,這裡的test只是相當於一個結構體名

int main()
{
    struct test t;//前面的“struct test”這個整體相當於一個變數型別說明符,說明變數t是屬於一個名為test的結構體型別
     
    t.a = 1;
    t.b = 2;

    printf("%d",t.a);
    return 0;

}