Problem with array and function(s)

arduino_new:

int distances[]={};

because it is doing exactly what you tell it to do; is to create and empty array.

try:

int distances[10]; //create array with 10 elements

keep in mind that in C/C++ the element starts at index 0.

But I do want it to create an empty array and simply append to the array at the nth index starting from n=0.

For example, this code works in a simulator such as tinkercad and it prints "6":

  int distances[]={};
  distances[0]=5;
  distances[1]=6;
  Serial.println(distances[1]);