Studying my final exam and stumbled upon this question with a previous exam:
Consider the following program written in a C-like notation:
int i = 1;
A[] = {4, 0, 1, 2};
void mystery05(int from, int to)
{
int temp;
temp = A[from];
A[from] = A[to];
A[to] = temp;
i = i + 2;
to = -1;
}
int main(void)
{
mystery05(A[i+2], A[i]);
}
In the table below, fill in the fields with the corresponding variable values after calling mystery05 in the main one. Each line corresponds to a specific style of parameter passing (i.e., use the specified style, not the default C-language semantics). Suppose arrays are indexed from 0.
style |___i___|__A[0]__|__A[1]__|__A[2]__|__A[3]__|
call-by-value |_______|________|________|________|________|
call-by-name |_______|________|________|________|________|
call-by-reference |_______|________|________|________|________|
call-by-value-result|_______|________|________|________|________|
I'm not sure how to do this, but if it was regular C semantics, I assumed that the answers would be
i = 3; A [0] = 4; A [1] = 2; A [2] = 1; A [3] = 0
source
share