Question about pointer arithmetic and types
So I would like to know how a pointer acts based on its type.
Code:
char *ptr; /* char == 1 byte */
So say the memory looks like this; and the pointer points to the byte of memory indicated with x's.
Code:
+--------+--------+--------+--------+
| | |xxxxxxxx| |
+--------+--------+--------+--------+
Now if I cast ptr to be of type int16 (2 bytes), will the memory then be pointing to a chunk that looks like this...?
Code:
ptr = (int16 *)ptr;
+--------+--------+--------+--------+
| | |xxxxxxxx|xxxxxxxx|
+--------+--------+--------+--------+
Also, if a pointer of type larger than one byte points to a chunk of memory, if I dereference that pointer and fill it with a value, will it start filling bits from right to left? Like this:
Code:
*ptr = 9;
+--------+--------+--------+--------+
| | |xxxxxxxx|xxxx1001|
+--------+--------+--------+--------+
And if I increment the pointer, it will increment by the type that it is? I.e.
Code:
ptr += 1;
+--------+--------+--------+--------+
| | |xxxxxxxx|xxxx1001|
+--------+--------+--------+--------+
|eeeeeeee|eeeeeeee| | |
+--------+--------+--------+--------+
ptr now points to blocks full of e's and if you were to modify, it starts filling from rightmost e to left...?
Also, if there are any tutorials on not only pointer arithmetic, but on situations where you cast a pointer to different type and start filling memory, etc... would be helpful. Thanks!