What happens in memory after return?
public class Test{ static int add (int m, int n){ return m+n; } public static void main (String[] args){ int a=1; int b=2; int c= add(a,b); } } Assume the above simple code. When I run the line int c = add(a,b); 32 bits of memory are allocated in the call stack for the integer variable c, then the method add is called with parameters 1 and 2. This will create two new areas in memory (in the call stack) for the parameters m and n and assign them the values 1 and 2, respectively. Now the return closes the method add and the memory allocated for m and n is set free again. Then afterwards the valu
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.