What are the Effects of this function

I am trying to understand the effects of following function:
This is just an example of the function...there is not much body of the function given. We just have to justify our answer. I am clueless on how to resolve this. Any help would be appreciated.


int& min(char*,int);
.
.
.
return(int2 <= int2) ? int1 : int2;


No I double checked there is no typo in this.....
The effect is undefined behavior.

Int1 and int2 are local variables of the function. What this function will return is a reference to int1. However, this is a problem because once the function returns, it is removed from the stack and all local variables (such as int1) of the function are "deleted". Thus, the function ends up returning a reference to a non-existing int.
Last edited on
Topic archived. No new replies allowed.