Okay. I have learned to do some pointer arithmetic and I have seen how far apart 2 elements in two different types of arrays are from each other. Here is the code:
#include <stdio.h>
#define MAX 10
int i_array[MAX] = { 0,1,2,3,4,5,6,7,8,9 };
int *i_ptr, *i2_ptr, *i3_ptr, count;
float f_array[MAX] = { .0, .1, .2, .3, .4, .5, .6, .7, .8, .9 };
float *f_ptr, *f2_ptr, *f3_ptr;
int main( void )
{
i_ptr = i_array;
i2_ptr = i_array[2];
i3_ptr = i_array[3];
f_ptr = f_array;
f2_ptr = &f_array[2];
f3_ptr = &f_array[3];
for (count = 0; count < MAX; count++)
{
printf("%d\t%f\n", *i_ptr, *f_ptr );
i_ptr++;
f_ptr++;
}
printf("\n%d\n", i2_ptr - i3_ptr );
printf("\n%d\n", f2_ptr - f3_ptr );
return 0;
}
For the future, I would like to understand why integer pointers don't need the "&" symbol before array names (with elements marked)?
P.s. If it would be the same for both the int array and float array it would look more logical.