あんまりよくわかってなかった構造体配列のポインタとアロー演算子
#include<stdio.h> //構造体test struct test { int a; int b; }; int main( void ) { //構造体配列の宣言 struct test hoge[10]; //配列の先頭アドレスを格納 struct test *hoge_pointer = hoge; //構造体の適当なメンバに適当な値を代入 hoge[0].a = 10; hoge[2].b = 22; //ドット演算子を用いたポインタによる値の参照 printf("hoge[0].a = %d\n" , (*hoge_pointer).a ); //アロー演算子を用いたポインタによる値の参照 printf("hoge[2].b = %d\n" , ( hoge_pointer + 2 )->b ); //アドレスの表示 printf("hoge_pointer = %p\n" , hoge_pointer ); return 0; }
実行結果
C:\Users\unasuke\Desktop>test
hoge[0].a = 10
hoge[2].b = 22
hoge_pointer = 0018FF04
-- Press any key to exit (Input "c" to continue) --
ソースコード見たら分かる……