| Author |
Message |
![]() ![]() ![]() ![]()
Myselfme
Junior Artist Username: Myselfme
Post Number: 273 Registered: 04-2011 Posted From: 107.77.87.88
Rating: N/A Votes: 0 (Vote!) | | Posted on Monday, August 24, 2015 - 04:20 pm: |
![]() ![]() ![]() ![]() ![]() |
Ownership transferred from function* |
![]() ![]() ![]() ![]()
Analog
Side Hero Username: Analog
Post Number: 4149 Registered: 05-2008 Posted From: 129.110.242.50
Rating: N/A Votes: 0 (Vote!) | | Posted on Monday, August 24, 2015 - 04:19 pm: |
![]() ![]() ![]() ![]() ![]() |
top(int hfhf...) { char* carray carray = calloc(num,sizeof(char)); modify_carray(xxx,xxx,carray) use_carray(xx,xxx,carray) free(carray); } modify_carray(int XX....,char* carray) { // write to carray } use_carray(....,char* carray) { // read carray } |
![]() ![]() ![]() ![]()
Myselfme
Junior Artist Username: Myselfme
Post Number: 272 Registered: 04-2011 Posted From: 107.77.87.88
Rating: N/A Votes: 0 (Vote!) | | Posted on Monday, August 24, 2015 - 04:19 pm: |
![]() ![]() ![]() ![]() ![]() |
Is it interview question? If yes, they is a possibility that they are getting into discussion on smart pointer, since the ownership is transferred to a function, use the shared_ptr in the main function, you can return unique_ptr from function I may be wrong |
![]() ![]() ![]() ![]()
Ysr2009
Side Hero Username: Ysr2009
Post Number: 2467 Registered: 03-2014 Posted From: 129.135.0.21
Rating: N/A Votes: 0 (Vote!) | | Posted on Monday, August 24, 2015 - 04:00 pm: |
![]() ![]() ![]() ![]() ![]() |
A( char **sCharOut) { .... (*sCharOut) = (char*) malloc(iLength * sizeof(char)); // Fill sCharOut } B() { char *sString=NULL; A( &sString ); free( sString ); }
 |
![]() ![]() ![]() ![]()
Maverick
Legend Username: Maverick
Post Number: 57974 Registered: 01-2008 Posted From: 108.171.130.188
Rating: N/A Votes: 0 (Vote!) | | Posted on Monday, August 24, 2015 - 03:56 pm: |
![]() ![]() ![]() ![]() ![]() |
what is the best way to return char* to the calling function?after a malloc of a local variable, need to return back to calling function..in that case who frees it and how to return? Happy Vizag |