Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
int a[20];
メモリ内の a[20] のアドレスが 100 であるとします。int のサイズは 4 ですa = 100, &a = 100, &a[4] = 116。&a + 4 = 420しかし、(&a + 4) を試すと、答えは 420です(GCC 、DEV-C 、VC でテストしました)。420 = 100 + 4 * sizeof (a[20]) = 100 + 4*(4*20)
a = 100, &a = 100, &a[4] = 116
&a + 4 = 420
420 = 100 + 4 * sizeof (a[20]) = 100 + 4*(4*20)
(上記の " = " は "等しい" を意味します)
そうですか?
&a20 個の要素を持つ int の配列へのポインタです (型は ですint (*)[20])。
&a
int (*)[20]
2 番目の式では、最初の要素へのポインターに評価されるため (タイプ のポインターに評価されます)、そうで&a + 4はありません。との値が同じであっても、ポインターの型が異なるため、ポインター演算の結果は異なります。a + 4aint*&aa
&a + 4
a + 4
a
int*