am having a function as given below
int* foo() {
int temp;
return(&temp); //address of temp variable.
what is wrong in writing the same function as
int foo() {
int temp;
return(&temp); //address of temp variable.
}
because the “&” operator returns the address of the memory location which is an integer.
Compiler doesn’t go by number logic. For it,
&tempis a pointer and justtempis an integer and are different types even though both are a stream of numbers underneath.Only a cast can convince a compiler of your logic.
Something like