我有以下結構裏面:如何創建一個指針結構
typedef struct bucket {
unsigned int contador;
unsigned int * valor;
} Bucket;
typedef struct indice {
unsigned int bs;
unsigned int valor;
unsigned int capacidade;
Bucket * bucket;
} Indice;
typedef struct tabela {
unsigned int bs;
Indice * indice;
} Tabela;
我想要做這樣的事情:
tabela->indice[2].bucket = &tabela->indice[0].bucket;
,但我得到段錯誤。
我怎樣才能得到tabela->indice[0].bucket
地址和聯繫到tabela->indice[2].bucket
。
謝謝!
1)在struct中創建指針:就像你做的一樣。 2)在使用它之前,確保*每個*指針實際上*指向某個東西。確保你已經分配了*分配的每個對象 - 並正確指定了指針! – paulsm4