Runtime Environment Part 3 L12
Runtime Environment Part 3 L12
Part 3
Prepared By:
Dr. D. P. Singh
Graphic Era Deemed to be University, Dehradun
Overview Scoping
• Scope:
Scope of a variable (v) in a program is the region of the
program in which use of v refers to its value of declaration.
int main()
{
printf("%d", too());
return 0;
}
Types of Scoping cntd…
2. Dynamic Scoping
int p=3;
Dynamic Scoping
hoo();
} Output:
void hoo(){ 2
printf("%d\n",p); 3
}
Parameter Passing Techniques
• Parameter Association:
• Positional
• Arguments associated with formals one by one.
• e.g. C, PASCAL, JAVA, C++
• Keyword
• e.g. Ada uses mixture
• procedure name(x,y: in real; z: in boolean)
• name(1.1,1.2, z=> true)
• name( z=>true,x=>1.1, y=>1.2)
Parameter Passing Techniques cntd…
1. Call by Value:
• At runtime prior to the call of procedure, the
parameter is evaluated and its actual value is put in a
location private to called procedure.
q := 20; Output: 12 22
foo(p,q);
write p,q;
}
Parameter Passing Techniques cntd…
3. Call by Value Result
4. Call by Name
• e.g. Algol
Call by Name cntd…
e.g.
procedure foo(X,I: integer)
begin
I=3;X=8;I=6;X=2;
end
The above procedure is called by the statement foo(P, Q[k]), this would
result in
begin
Q[k]=3; P=8; Q[k]=6; P=2;
end
Thank You