Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning a value from function

How does returning a value from a function internally works ?

See this example..

alt text

like image 763
Saurabh Gokhale Avatar asked Apr 24 '10 14:04

Saurabh Gokhale


People also ask

Can a function return any value?

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.

What is function 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.


1 Answers

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.

like image 64
Brett Kail Avatar answered Oct 07 '22 01:10

Brett Kail