Below is the code I am trying to test out. I have a table size 2x4 for which I am trying to pass the address to a pointer which is going to be used by a lookup function. The code works as expected and I am receiving the correct values but I am getting the following warning:
warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
Below is the code:
#include <stdio.h>
float lookup(float const *lookuppointer, int lookupindexX)
{
float value;
value = lookuppointer[lookupindexX];
return(value);
}
int main()
{
float cal1[2][4] = {{0,1,2,3},{4,5,6,7}};
float value;
float *pointer[4];
*pointer = cal1;
printf("The address of pointer is %p \n", pointer);
value = lookup(*pointer,6);
printf("The value is %f \n", value);
printf("cal1 = %f", cal1[1][2]);
return 0;
}
Also for some reason I need to add a size when defining the pointer, and I can put any number and it works (e.g. float *pointer[n]), I do not understand the reason behind it as well.