$24.99
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 is
2. A, B, C : Integer ;
1
3. procedure Sub1 is
4. D, E : Integer ; 5. begin −− of Sub1
6. . . .
7. end; −− of Sub1
8. procedure Sub2 is 9. C, D : Integer ;
10. procedure Sub3 is
11. B, D, F: Integer ; 12. begin −− of Sub3
13. . . .
14. end; −− of Sub3 15. begin −− of Sub2
16. . . .
17. end; −− of Sub2 18. begin −− of Main
19. . . .
20. end; −− of 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