J
J
Dear Advanced users,
Here are parts of a code sample and I need to find out a few things from
this.
Please tell me your input. I am supposed to get others help as well to make
the answers as accurate as possible.
char * p;
p=test();
char * test() {
char buf[8];
return (char *) buf;
}
1. If this is reasonable or not and why.
2. Would this work at all?
3. Why is this a good practice?
4. How, exactly, could one get a second ¡®char *¡¯ to use back from this
function? In other words, how can this function be modified to return a
¡®char *¡¯ from the function, and an additional ¡®char *¡¯ value in one
function call. Please make sure that your answer will work even if the size
of the char * desired is not known in the outside calling function.
Include statements in called and calling functions.
Thanks in advance..
Joon
Here are parts of a code sample and I need to find out a few things from
this.
Please tell me your input. I am supposed to get others help as well to make
the answers as accurate as possible.
char * p;
p=test();
char * test() {
char buf[8];
return (char *) buf;
}
1. If this is reasonable or not and why.
2. Would this work at all?
3. Why is this a good practice?
4. How, exactly, could one get a second ¡®char *¡¯ to use back from this
function? In other words, how can this function be modified to return a
¡®char *¡¯ from the function, and an additional ¡®char *¡¯ value in one
function call. Please make sure that your answer will work even if the size
of the char * desired is not known in the outside calling function.
Include statements in called and calling functions.
Thanks in advance..
Joon