syntaxly , 2 is wrong, because it try to return memory on the stack, when v() is finished the the memory on stack is released. the returned pointer ref to invalid memory.
1 and 3 are exactly the same except in debug build 1 will alloc one pointer on stack, in optimized mode, these 2 function will all probably return a constant address,semanticly, 1&3 are all wrong. The string "result of function v()" is allocated by compiler in Initialized data segement, but, notice, logically, it should be constant,although u can modify it.
const char^ v()
{
return "result of function v()";
}
will be the best way
1 and 3 are exactly the same except in debug build 1 will alloc one pointer on stack, in optimized mode, these 2 function will all probably return a constant address,semanticly, 1&3 are all wrong. The string "result of function v()" is allocated by compiler in Initialized data segement, but, notice, logically, it should be constant,although u can modify it.
const char^ v()
{
return "result of function v()";
}
will be the best way