Starting from:

$29

Programming Languages Concepts Homework 2

CSE 461: Programming Languages Concepts

Homework 2:
late submission will be allowed for this assignment, since I want to
release the answer key early for you to prepare for midterm 1. Total: 15
points.
Submission: Please submit your homework via Gradescope. During
submission, you need to match pages and homework questions.
You can watch a video about how to do that via Gradescope below:
https://www.youtube.com/watch?time_continue=1&v=KMPoby5g_nE&feature=
emb_logo
If you submit a scanned version of your on-paper answers, please make sure
your scanned version is legible.
1. (4 points) In class, we discussed static local variables in C. Answer
each question below; if necessary, find and consult a reference on the
C language (cite your source in your answer).
(a) For a non-static local variable in a C function, what is its scope
and what is its lifetime?
(b) For a static local variable in a C function, what is its scope and
what is its lifetime?
(c) For a non-static global variable in C, what is its scope and what
is its lifetime?
(d) For a static global variable in C, what is its scope and what is its
lifetime?
2. (3 points) Find some online material to learn PHP’s namespace mechanism (cite your source). Explain briefly how it works and its benefits.
3. (8 points) Consider the Ada program given below. You will be asked
to determine which variables are visible in a number of different situations. In each case, identify each variable by its name and the line
number of its declaration.
1 . procedure Main i s
2 . A, B, C : I n t e g e r ;
1
3 . procedure Sub1 i s
4 . D, E : I n t e g e r ;
5 . begin −− o f Sub1
6 . . . .
7 . end ; −− o f Sub1
8 . procedure Sub2 i s
9 . C, D : I n t e g e r ;
1 0. procedure Sub3 i s
1 1. B, D, F: I n t e g e r ;
1 2. begin −− o f Sub3
1 3. . . .
1 4. end ; −− o f Sub3
1 5. begin −− o f Sub2
1 6. . . .
1 7. end ; −− o f Sub2
1 8. begin −− o f Main
1 9. . . .
2 0. end ; −− o f Main
(a) Assuming that static scoping is used, say which variables are
visible in the bodies of each of the procedures: Main, Sub1, Sub2
and Sub3.
(b) Assuming that dynamic scoping is used and the calling sequence
is Main calls Sub1; Sub1 calls Sub2; Sub2 calls Sub3, say which
variables are visible in Sub3.
(c) Assuming that dynamic scoping is used and the calling sequence
is Main calls Sub2; Sub2 calls Sub3; Sub3 calls Sub1, say which
variables are visible in Sub1.
(d) Assuming that dynamic scoping is used and the calling sequence
is Main calls Sub2; Sub2 calls Sub1, say which variables are visible
in Sub1.
2

More products