hi people,
im trying to return an array. here is my function.
string *split(){
string *ptr;
string data[3];
ptr = data;
data[0] = "apple";
data[1] = "orange";
data[2] = "durian";
return ptr;
}
i tried calling in main but im getting run time errors
int main(){
string *ptr = split();
cout << ptr[0];
cout << ptr[2];
cout << ptr[3];
return 0;
}
the run time error im getting is segmentation fault.
Please help. tks
string data[3];
ptr[3];
Accessing out of array bounds
hi,
sorry that was a typing error.
i even tried assigning to data[0] only and in main(), cout << data[0]. it still gives an error
Last edited on
hey people,
i managed to resolve it. tks anw