// functions that converts a number into an array
int *initialiser(int number)
{
int array[20];
for (int i = 19; i >= 0; i--)
{
array[i] = number % 10;
number /= 10; // number = number/10
}
return array;
}
//I get this error
primaryAddSub.cpp: In function 'int* initialiser(int)':
primaryAddSub.cpp:21:9: warning: address of local variable 'array' returned [-Wreturn-local-addr]
int array[20];
^~~~~
I can use static int array[20]; but the function will return the same result each time I call it.
std::arrayor astd::vectorinstead.std::array<int, 20> initialiser(int number)std::vector<int> initialiser(int number) { std::vector<int> array(20); ... }and the rest would work too. Only the call site would perhaps need some adjustment - depending on what it looks like now.void foo(int (&x)[100]);