problem in return double pointer

Status
Not open for further replies.

krishna_1980

Junior Member level 3
Joined
Jan 4, 2006
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,457
return double pointer

how to retern a double pointer from a function.y the following code is not working..
char **func(void);
main()
{
char **ch;
ch=func();
prinyf("%s%s",ch[0],ch[1]);
}
char **func()
{
char *p[2]={"a","b"};
char **k;
k=p;
return(k);
}
 

returning a double pointer

The local variables will be destroyed after the function where they are declared is finished. Thus, you cannot use the result. One simple method is to use a global variable instead of the local variable.
 

you have to use malloc to allocate memory for pointer!!!
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…