How does returning a value from a function internally works ?
See this example..
If a function is defined as having a return type of void , it should not return a value. In C++, a function which is defined as having a return type of void , or is a constructor or destructor, must not return a value. If a function is defined as having a return type other than void , it should return a value.
A function that returns a value is called a value-returning function. A function is value-returning if the return type is anything other than void . A value-returning function must return a value of that type (using a return statement), otherwise undefined behavior will result.
The JVM uses a value stack to hold values, and the stack is shared across all method calls on that thread. Normally, when a non-void method returns, the return value is pushed on the stack, and the caller pops it off the stack and either uses it or discards it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With