Can you use data type double or float for an array? ie
1 2 3 4 5
double n[];
or
float a;
float m[a];
My code wont accept me changing the data type..will on accept int data type. I get the following error when I try to change the array to double or float..
It's perfectly fine to have an array of floats or doubles.
float farray[3] = {3.14, 1.59, 6.53};
However, you won't be able to access an index of an array if the index is a floating point value - which makes sense if you think about it. What exactly would be the 1.23th element? It doesn't make any sense, which is why would either cast to an integer, or use an integer in the first place.
1 2 3 4 5 6 7
float farray[3];
float index = 1.23;
farray[(int)index] = 0.0;
//which, in this case, is the same as
farray[1] = 0.0;
You can have an array of any data type. The offset must be a signed or unsigned integer(yes it is possible to have negative offsets). To get even more confusing you can interchange them. array[1] == 1[array]