B 15 25 A 15 50 Output with dynamic scope (non-locals are impacted by calling sequence): B 15 55 A 15 55 Parameter Passing C Arguments (i.e., actual parameters) arrays are passed by reference - passed to a function. by default, everything else is passed by value; Arguments might be however, an address of the argument can be identifiers, constants or passed by using the & operator // call expressions (which might determineMinMax(gradeM, iNumEntries, involve function calls) &dMin, &dMax); Parameters (i.e., formal // function declaration represent parameters) - void determineMinMax(double gradeM[], the arguments in the int iNumEntries called function , double *pdMin, double *pdMax) { Parameter transmission techniques: … By Value - the value of the argument if (gradeM[i] > *pdMax) is passed and becomes the *pdMax = gradeM[i]; value of the formal … parameter } By Reference - conceptually a pointer (usually the location of the PL/I argument) is transmitted; uses by reference function can modify the instead of the programmer dereferencing a argument; often called by parameter in the called function, the compiler address parameter did that under the covers. passing By Name - transmit an unevaluated /* call */ argument, allowing the determineMinMax(gradeM, iNumEntries, called function to evaluate min, max); it /* function declaration */ determineMinMax: PROC (gradeM, Note: many languages use but By Value, iNumEntries, min, max); pass references to objects (i.e., the pointer's DCL gradeM(*) FLOAT, value is copied not the address of the iNumEntries FIXED BIN, variable). You will find many incorrect sites min FLOAT, which incorrectly state a language has by max FLOAT; reference parameter passing since it passes … IF gradeM(i) > max a reference. It is better to call this by value max = gradeM(i); object reference. … END determineMinMax; Java uses by value and by value object reference
B 15 25 A 15 50 Output with dynamic scope (non-locals are impacted by calling sequence): B 15 55 A 15 55 Parameter Passing Arguments (i.e., actual parameters) - passed to a function. Arguments might be identifiers, constants or expressions (which might involve function calls) Parameters (i.e., formal parameters) - represent the arguments in the called function Parameter transmission techniques: By Value - the value of the argument is passed and becomes the value of the formal parameter By Reference - conceptually a pointer (usually the location of the argument) is transmitted; function can modify the argument; often called by address parameter passing By Name - transmit an unevaluated argument, allowing the called function to evaluate it Note: many languages use By Value, but pass references to objects (i.e., the pointer's value is copied not the address of the variable). You will find many incorrect sites which incorrectly state a language has by reference parameter passing since it passes a reference. It is better to call this by value object reference. C arrays are passed by reference by default, everything else is passed by value; however, an address of the argument can be passed by using the & operator // call determineMinMax(gradeM, iNumEntries, &dMin, &dMax); // function declaration void determineMinMax(double gradeM[], int iNumEntries , double *pdMin, double *pdMax) { … if (gradeM[i] > *pdMax) *pdMax = gradeM[i]; … } PL/I uses by reference instead of the programmer dereferencing a parameter in the called function, the compiler did that under the covers. /* call */ determineMinMax(gradeM, iNumEntries, min, max); /* function declaration */ determineMinMax: PROC (gradeM, iNumEntries, min, max); DCL gradeM(*) FLOAT, iNumEntries FIXED BIN, min FLOAT, max FLOAT; … IF gradeM(i) > max max = gradeM(i); … END determineMinMax; Java uses by value and by value object reference
cs3723OverviewWO.docx