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
461:, Concepts, Homework, Languages, Programming, solved
[SOLVED] Cse 461: programming languages concepts homework 2
$25
File Name: Cse_461__programming_languages_concepts_homework_2.zip
File Size: 471 KB
Reviews
There are no reviews yet.