Overview
How should we submit HW2?
Same as last time. Share github repo. Send a note to the grader (csc207-01-grader@grinnell.edu).
Yesterday’s labs were about ways to find/deal with incorrect code.
c2f
issues
sum
issues
expt
issues
int fact(n) { if (n == 0) 1 else n*fact(n-1); }
x = new Counter();
z = 2
this
also gets put on the stack
and points to the object whose method we called.What are “pass by value” and “pass by reference”?
In “pass by value”, you put the value of each actual parameter into the slot on the stack for the formal.
In “pass by reference”, you put the address of each actual parameter into the slot on the stack for the formal.
int i;
void f(int x) { ... }
...
f(i);
Pass-by-value
Stack
+----------+
x | 5 |
+----------+
i | 5 |
+----------+
Pass-by-reference
Stack
+----------+
x | &i |
+----------+
i | 5 |
+----------+