



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Detailed informtion about Type parameters and parameterized types, Parameters, actual parameters, Parameterization mechanisms, Parameter-Passing Methods, Semantic Models of Parameter Passing.
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Type parameters and parameterized types Parameters The parameters in the subprogram header are called formal parameters. They are sometimes thought of as dummy variables because they are not variables in the usual sense: In some cases, they are bound to storage only when the subprogram is called, and that binding is often through some other program variables. Subprogram call statements must include the name of the subprogram and a list of parameters to be bound to the formal parameters of the subprogram. These parameters are called actual parameters. The binding of actual parameters to formal parameters is done by simple position: The first actual parameters is bound to the first formal parameter and so forth. Such parameters are called positional parameter. When lists are long, however it is easy for the program writer to make mistakes in the order of parameters in the list. One solution to this problem is to provide keyword parameters , in which the name of formal parameter to which an actual parameter is to be bound is specified with actual parameter. The advantage of keyword parameters is that they can appear in any order in the actual parameter list. SUMER(LENGTH => MY_LENGTH, LIST => MY_ARRAY, SUM => MY_SUM);
Parameterization mechanisms Parameter-Passing Methods Parameter-passing methods are the ways in which parameters are transmitted to and/or from called subprograms.
Semantic Models of Parameter Passing Formal parameters are characterized by one of three distinct semantics models : (1) They can receive data from the corresponding actual parameter, in mode (2) They can transmit data to the actual parameter, out mode, (3) They can do both. inout mode
Implementation Models of Parameter Passing
Pass-By-Value ( In-Mode)
subprogram termination, the value of the formal parameter is transmitted back to the actual parameter.
Pass-By-Reference
Example program in C Language #include <stdio.h> void swapnum(int *i, int *j) { int temp = i; ij == j;temp; } int main(void) { int a = 10; int b = 20; swapnum(&a, &b); printf("A is %d and B is %d\n", a, b); return 0; }
Pass-By-Name
E.g Algol uses the powerful mechanism pass-by-name.