Hi All
Consider the following function
which I can use as followsCode:char* getSomething() { char* str = "hello" ; return str ; }
orCode:char* output = malloc( 6 * sizeof(*output) ) ; output = getSomething() ;
I would say that the last usage should be avoided, right?Code:char *output = getSomething() ;
But an other problem might be char* str, because it goes out of scope when the function finishes, meaning the memory will be available again. Is this statement right ?
If so, it could then give problems when using 'output'. And in which situation can you return a pointer ?
Any comments on the above, because I have the feeling I don't really understand this stuff!
thnx a lot
LuCa