0
Pointer to memory
I have an array declared with new operator, and I pass it to a function. That receives it as a pointer parameter. Now in this function I have an other dynamic array to store result. Problem is : Memory of passed array should be free in the end of this function, its pointer should point the allocated memory in this function and it can b used in calling function without return pointer to memory.
5 Antworten
+ 5
I have wrote a example for you to illustrate. This is how you accomplish that.
https://code.sololearn.com/cZmCzS4SxXBM/?ref=app
+ 2
can you share your code here?
+ 1
thanks Tanay
I got it.
you used double pointer to acquire this.
thanks 😊
0
please provide a sample code. Your explanation is not clear.
0
for example
void f1 (){
int* p1 =new int [30];
f2 (p1);
}
bool f2 (int *p){
int* p2=new int [30];
//some manipulation on p and store result in p2 via loop
//delete memory of p and store memory address pointed by p2 in p so that it can be accessed by p1 in f1.
return true;
}
//is it possible in any way ?