T
Terence
I need some clarification with pointer arithmetics on void *.
Example 1:
========
char s[100];
char *ptr = s;
ptr += 1;
// I assume ptr is increased by 1 byte, pointing to the 2nd element in the array, right?
Example 2:
=======
int i[100]; // suppose the size of an int is 4 bytes
int *ptr = i;
ptr += 1; // so is ptr increased by 4 bytes in here?
Example 3:
=======
int i[100];
void *ptr = i;
ptr += 1; // So how many bytes is the ptr increased by here?
// Will it point to the 2nd element of the array.
If I know the byte-size of elements in the array, but I don't know the actual type.
How can I make the void * pointer points to the next element of the array?
Thanks,
Terence
Example 1:
========
char s[100];
char *ptr = s;
ptr += 1;
// I assume ptr is increased by 1 byte, pointing to the 2nd element in the array, right?
Example 2:
=======
int i[100]; // suppose the size of an int is 4 bytes
int *ptr = i;
ptr += 1; // so is ptr increased by 4 bytes in here?
Example 3:
=======
int i[100];
void *ptr = i;
ptr += 1; // So how many bytes is the ptr increased by here?
// Will it point to the 2nd element of the array.
If I know the byte-size of elements in the array, but I don't know the actual type.
How can I make the void * pointer points to the next element of the array?
Thanks,
Terence