Array pointer passed one method to another.

How to write function whose can use pointer returned from another function.

int* func00(){
int r[2] = {0};
r[0] = 3;
r[1] = 4;
return r;
}

void func(int* r){
// here not work good
cout << r[0] << endl;
}

void pointer(){
func(func00());
}
You are returning a pointer to a local variable in func00() that is destroyed when the function exits. If you must do it as you are, you'll need to dynamically allocate memory inside func00() and return a pointer to that. Though you'll then need to delete[] outside of where it was created which is not a good idea IMO.
Topic archived. No new replies allowed.