c.のポインター、配列、およびメモリ位置の簡単な説明を他の回答に追加する価値があると思います。
まず、C の配列は、配列内の項目数を保持するのに十分な大きさの単なるメモリ ブロックです ( http://www.cplusplus.com/doc/tutorial/arrays/を参照) 。
だから私たちが言ったら
int[5] example;
example[0] = 1;
example[1] = 2;
example[2] = 3;
example[3] = 4;
example[4] = 5;
int が 32 ビットであると仮定すると、メモリのブロックは 5*32 ビット = 160 ビットの長さになります。C は低水準言語であるため、できるだけ効率的にしようとするため、配列に関する最小限の情報を格納します。この場合、可能な限り最小限の量は最初の要素のメモリ アドレスです。したがって、例のタイプは次のように表現できます
int *example;
または例はintを指します。配列内の項目を取得するには、例に格納されているアドレスに正しい数値を追加し、そのメモリ アドレスの数値を読み取ります。メモリが次のように見えると仮定すると
Memory Address = Value (ints take up 4 bytes of space)
1000 = 1 <-- example
1004 = 2
1008 = 3
1012 = 4
1016 = 5
そう
int i = example[3]; //The 4th element
次のように表現できます
int i = *(example + 3 * sizeof(int));
int i = *(example + 3 * 4);
int i = *(1000 + 12);
int i = *(1012); // Fetch the value at memory location 1012
int i = 4;
sizeof(int) は 4 です (int は 32 ビット、つまり 4 * 8 ビット バイトです)。加算を行おうとしている場合は、8 ビットまたは 1 * 8 ビット バイトの char が必要です。
コードに戻ります
char* p; // declare p as a pointer to a char/
p = (char *)a; // point p at memory location 3000
// p[b] would be the 21st element of the "array" p =>
// p[20] =>
// p + 20 * sizeof(char) =>
// p + 20 * 1 =>
// p + 20 =>
// 3000 + 20 =>
// 3020
// the & operator in c gets the address of the variable so
sum = (int) &p[b];
// &p[b] => find the address pointed to by p[b] => 3020
// (int) casts this pointer to a int.
そのため、sum には配列の 21 番目の要素のアドレスが割り当てられます。
長々と説明。