As the declared array has automatic storage duration then it will not be alive after exiting the function.
So you need either to allocate it dynamically or to declare it with the storage class specifier static as for example
static Car* cars[1000] = {};
Functions may not have the return type that is an array type. You can return a pointer either to the first element of an array as for example
Car** pop( void ){
static Car* cars[1000] = { 0 };
return cars;
}
or to the whole array like
Car ( * pop( void ) )[1000] {
static Car* cars[1000] = { 0 };
return &cars;
}
or can return a reference to the array
Car ( & pop( void ) )[1000] {
static Car* cars[1000] = {};
return cars;
}
c++, then it is better to returnstd::vector<Car>instead of pointers, pointers arecstylepopshould not return an array.