Float array print issue

someone plz explain why this is not working
its not printing all the elements from x;

void setup()
{
Serial.begin(9600);
}
float x[]= {1.3,2.5,5.3};
void loop()
{
int i=2;
float value=x[i];
Serial.println(value);
i=3;
value=x[i];
Serial.println(value);
}

The array only has three elements, so no element with the index 3.

Did you try using

Serial.println(  x[0] );
Serial.println(  x[1] );
Serial.println(  x[2] );

?

Ordinal reference position and the number of array cells are different numbers. Ordinal reference starts at 0. Perhaps this lesson may be of help, C++ Arrays

Sorry
i actually wanted to ask this,

const float January_Sunrise[31] PROGMEM={6.41,6.42,6.42,6.43,6.43,6.43,6.43,6.44,6.44,6.44,6.45,6.45,6.45,6.45,6.45,6.45,6.46,6.46,6.46,6.46,6.46,6.46,6.46,6.46,6.46,6.46,6.46,6.46,6.46,6.46,6.46};
void setup()
{
Serial.begin(9600);
}
void loop()
{
for(int i=0;i<=30;i++)
{
Serial.println(January_Sunrise[i]);
}
}

this code isn't working

Please edit your posts with the code, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code (e.g. [] vs. []).

It's described in How to get the best out of this forum.

What does that mean?

Its not printing all the elements in January_Sunrise[i] , instead its printing zeros

You can't read PROGMEM variables as you do. See PROGMEM - Arduino Reference

The code, post#9, won't even compile.

Did you count the number of elements in {6.41, 6.42, 6.42, 6.43, 6.43, 6.43, 6.43, 6.44, 6.44, 6.44, 6.45, 6.45, 6.45, 6.45, 6.45, 6.45, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46}; and compare it to the number 30?

Did you try

const float January_Sunrise[34] = {6.41, 6.42, 6.42, 6.43, 6.43, 6.43, 6.43, 6.44, 6.44, 6.44, 6.45, 6.45, 6.45, 6.45, 6.45, 6.45, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46, 6.46};
void setup()
{
  Serial.begin(9600);
}
void loop()
{
  for (int i = 0; i <= 30; i++)
  {
Serial.print( "element number ");
Serial.print ( i );
Serial.print( " the info is ");
    Serial.println(January_Sunrise[i]);
  }
}

Notice the changes of no PROGMEM and the number 34?

You have a 30 element array.
A 30 element array has no element with the index 30.

Dont double post please !!

1 Like

i want to store it in Flash

removing progmem will print it

So, read it from flash.

nope have 31 element

If you changed your code, post it. Did you do as per post#9 for the other thing?

how to?

Please don't waste my time - if you'd tried to cram 31 elements into a 30 element array, the compiler would have given you an error

You've already been given the answer

The array as posted in post number 4 does NOT have 30 elements being assigned to the array, it has 34 elements. The code from post #9 does not compile. The error message is quite clear, the code from post#9 did not print all 0's.

i see 31 elements only