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.

17th Jun 2018, 12:37 PM
Azam
Azam - avatar
5 Respostas
+ 5
I have wrote a example for you to illustrate. This is how you accomplish that. https://code.sololearn.com/cZmCzS4SxXBM/?ref=app
17th Jun 2018, 5:52 PM
Tanay
Tanay - avatar
+ 2
can you share your code here?
17th Jun 2018, 1:35 PM
Tanay
Tanay - avatar
+ 1
thanks Tanay I got it. you used double pointer to acquire this. thanks 😊
18th Jun 2018, 5:59 AM
Azam
Azam - avatar
0
please provide a sample code. Your explanation is not clear.
17th Jun 2018, 3:43 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
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 ?
17th Jun 2018, 4:59 PM
Azam
Azam - avatar