I have an array of unsigned 8 bit integer, however the length of this array can be higher than 255. I want to use pointer arithmetics instead of array indexing.
Can someone explain me if the following code is acceptable or not? My doubt is that the ind
variable has a different type with respect to buff
and this might be seen as bad programming.
#include <stdio.h>
#include <stdint.h>
int main(){
uint8_t buff[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int16_t ind;
ind = 1;
printf("%u\n", *(buff + 1));
printf("%u\n", *(buff + ind));
}
Godbolt shows a small difference between *(buff + 1)
and *(buff + ind)
but it seems to work.