Pascal (i think) passing by name, reference, value and value-result
Posted on 2004-11-28
This may be kind of long but hopefully not too hard. This is the Pascal section so can you tell me if this program segment is written in Pascal or not (I don't know this language by the way...obviously).
program Main (...);
var Y: integer;
begin X := X+1; write (X,Y) end;
Y :=1; P(Y); write(Y)
Is this in Pascal? This matters only so I ask this question in the right section. I don't know either way. What I do need to know is how to determine the following:
I know that passing by value means passing the parameter to the formal parameter; that passing by reference means that a pointer is used or has the potential to be used by a subprogram; passing by value-result is when the formal parameter is a local variable with the same data type as the parameter; and that passing by name is a subprogram call that substitutes for the body of subprogram.
I know in theory what all of these mean but because of my ignorance in Pascal, how do I follow the execution of these 4 types of parameters? I know that if you follow the execution of this segment (by transmitting Y to P) using each one of these methods (by reference, by name, etc.), the program will output several numbers.
Can you give me tips/resources/any help on how to determine what the output of this program segment would be using each of these four methods? If this segment is not in Pascal can you tell which language it is so I can ask this question in the right section?
I appreciate it so much. Thank you :)