Both outputs are undefined behavior, because the return value of the function is a reference to a local variable, and the local variable will be destroyed when the function ends, so using the returned reference outside the function is undefined. As for the first output of 20, it may have something to do with the compiler. Different compilers handle undefined behavior differently. If you change the compiler, it may output random numbers twice.
Both outputs are undefined behavior, because the return value of the function is a reference to a local variable, and the local variable will be destroyed when the function ends, so using the returned reference outside the function is undefined. As for the first output of 20, it may have something to do with the compiler. Different compilers handle undefined behavior differently. If you change the compiler, it may output random numbers twice.