Crosses Initialization in switch case with different size of array per case

void setup()  {
  Serial.begin(9600);
}


void loop()
{
  time_Text(2);
}

void time_Text(int PastTo_val) {
  switch (PastTo_val) {
    case 1:
      {
        int tPTT_y[] = {11, 11, 11, 11};
        int tPTT_x[] = {6, 7, 8, 9};
      }
      break;
    case 2:
      {
        int tPTT_y[] = {11, 11};
        int tPTT_x[] = {10, 11};
      }
      break;
  }

  int n_tPTT = sizeof(tPTT_x) / sizeof(tPTT_x[0]);

  Serial.print(tPPT_y);
  Serial.print(" : ");
  Serial.print(tPPT_x);
  Serial.print(" : ");
  Serial.println(n_tPPT);

}

Hello,

I have a case that i need to assign different kind of array value (with different size per case), and then find the size of the array, and print it, the problem is that the tPTT_y and tPTT_x is a local variable which cannot be accessed outside of the case function. i have tried to declare it before the switch function but i cannot give a size number because the size is different per case, how could i solve this?

Thank you

this method uses heap, thus the importance of calling delete:

void setup()  {
  Serial.begin(9600);
}

void loop()
{
  Serial.println(F("Using 2:"));
  time_Text(2);
  Serial.println(F("Using 1:"));
  time_Text(1);
  delay(1000);
}

void time_Text(int PastTo_val) {
  int* x_arr = nullptr;
  size_t x = 0;
  switch (PastTo_val) {
    case 1:
      x_arr = new int[4]{6,7,8,9};
      x = 4;
      break;
    case 2:
      x_arr = new int[2]{10,11};
      x = 2;
      break;
  }

  for (size_t i = 0; i < x; i++) {
    Serial.println(x_arr[i]);
  }
  // IMPORTANT:
  delete[] x_arr;
}