int Y(){
int* b = new int(6);
return b*;
}
This has a syntax error. To dereference b
, you would do *b
. Nonetheless, this is a very bad implementation because it leaks memory. The dynamically allocated int
will never be destroyed.
int& Z(){
int b = 6;
return b;
}
This is also bad because you are returning a reference to a local variable. The local variable b
will be destroyed when the function returns and you'll be left with a reference to a non-existent object.