Complete the following tracing tables. Each of them has a short method declarati
ID: 3669384 • Letter: C
Question
Complete the following tracing tables. Each of them has a short method declaration followed by short client code that invokes the method. Carefully complete each tracing table starting from the client code and tracing over the method call and through the method body.
Swapping for primitive types:
Statement Variable Values private static void swap1(int i1, int i2) { i1 =i2 = int tmp = i1; i1 =
i2 =
tmp = i1 = i2; i1 =
i2 =
tmp = i2 = tmp; i1 =
i2 =
tmp = } Start tracing here int x = 7, y = 12; x =
y = swap1(x, y); x =
y =
Explanation / Answer
Statement
Here we are doing call by value so after calling swap function, values of x and y will be same, although in swap1 function values of i1 and i2 will be changed with in that function
x = 7
y = 12
Statement
Variable Values private static void swap1(int i1, int i2) { i1 = 7i2 = 12 int tmp = i1; i1 = 7
i2 = 12
tmp = 7 i1 = i2; i1 = 12
i2 = 12
tmp = 7 i2 = tmp; i1 = 12
i2 = 7
tmp = 7 } Start tracing here int x = 7, y = 12; x = 7
y = 12 swap1(x, y);
Here we are doing call by value so after calling swap function, values of x and y will be same, although in swap1 function values of i1 and i2 will be changed with in that function
x = 7
y = 12