I have a function which contains more than one array and I want to use those two arrays in my main function in this way
void fun () //which data type should I place here int OR char ?
{
int array[4]={1,2,3,4}
char array2[3]={'a','b','c'}
return array,array2;
}
int main(){
int array1[4];
char array2[3];
array1=fun(); is it possible to get these array here ?
array2=fun();
}
If you really want to return arrays, you could put them in a std::pair of std::arrays:
#include <array>
#include <utility>
auto fun() {
std::pair<std::array<int, 4>, std::array<char, 3>> rv{
{1, 2, 3, 4},
{ 'a', 'b', 'c' }
};
return rv;
}
int main() {
auto[ints, chars] = fun();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With