what the result will be after execute the C-like program, if the parameter passing mechanism is pass-by-name-result?
procedure swap(int x, int y){
int t = x;
x = y;
y = t;
}
main(){
int v = 1;
int list[5] = {1,3,5,7,9};
swap(v, list[v]);
}
(Note: I’m assuming that the question is about call-by-name as the question’s body suggests – not call-by-value-result as the title suggests.)
When using call-by-name you can figure out the result of a function call by inserting the function’s body at the call site and replacing each occurrence of the parameter names in the function’s body with the (unevaluated) arguments.
In this case that means replacing each occurrence of
xwithvand each occurrence ofywithlist[v]. If you do that and execute the resulting code in your head, you’ll see what the result is.