How to pass char* as refrence in a funstion?
ridhimasatam
0
Newbie Poster
Recommended Answers
Jump to Postpass char** which is a pointer to a pointer, like this
void foo( char ** ptr) { *ptr = new char[255]; } int mian() { char *ptr = 0; foo( &ptr ); <snip> return 0; }
Jump to PostOr of course you can pass it by C++ reference like:
void foo( char *& ptr) { ptr = new char[255]; } int mian() { char *ptr = 0; foo( ptr ); <snip> return 0; }
Jump to Postbased on these two methods is there any gain over one, is one safer than another?
All 10 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
thekashyap
193
Practically a Posting Shark
Killer_Typo
82
Master Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
thekashyap
193
Practically a Posting Shark
risa
0
Light Poster
thekashyap
193
Practically a Posting Shark
ridhimasatam
0
Newbie Poster
Killer_Typo
82
Master Poster
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.