Adding i to a pointer value yields a pointer to the i'th object of the same type in a sequence. Assuming the declarations
char *cp = 0x8000;
short *sp = 0x8000;
long *lp = 0x8000;
the following is true:
char char * short short * long long *
---- ------ ----- ------- ---- ------
+---+ +---+ +---+
0x8000 | | <-- cp | | <-- sp | | <-- lp
+---+ | | | |
0x8001 | | <-- cp + 1 | | | |
+---+ +---+ | |
0x8002 | | <-- cp + 2 | | <-- sp + 1 | |
+---+ | | | |
0x8003 | | <-- cp + 3 | | | |
+---+ +---+ +---+
0x8004 | | <-- cp + 4 | | <-- sp + 2 | | <-- lp + 1
+---+ | | | |
... ... ...
cp points to a 1-byte object, sp points to a 2-byte object, and lp points to a 4-byte object, all starting at address0x8000.
The expression cp + 1 has type char * and the value 0x8001 - it yields a pointer to the first char object following the object pointed to by cp.
The expression sp + 1 has type short * and the value 0x8002 - it yields a pointer to the first short object following the object pointed to by sp.
And the expression lp + 1 has type long * and the value 0x8004 - it yields a pointer to the first long object following the object pointed to by lp.
This is exactly how array subscripting works - the expression a[i] is defined as *(a + i) - given a pointer value specified by a, offset i elements (not bytes!) from that address and dereference the result.
Arrays are not pointers - array expressions "decay" to pointer values under most circumstances, precisely because of the semantics above. When you write something like
a[i] = some_value;
the expression a is automatically converted from type "N-element array of T" to "pointer to T" and the value of the expression is the address of the first element of a. The exceptions to this rule are:
when the array expression is the operand of the sizeof, _Alignof, or unary & operators;
when the expression is a string literal used to initialize a character array in a declaration, like char foo[] = "some string";
{}after theforto make the loop body obvious. And at the very least, you should indent theprintfand place it on the following line after thefor.10from the code and figure out how to make the compiler count the elements for you.arrayis equivalent to the address of the first element:&array[0]#2:array+iis equivalent to the address of the i-th element:&array[i]#3:*(array+i)is equivalent to the value at the i-th element:array[i]