CSE 461: Programming Languages ConceptsHomework 2:Solved

20.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . pdf solution files instantly, after Payment

Description

5/5 - (2 votes)
  1. (8 points) Consider the C 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.
    • int h, i;
    • void B(int w) {
    • int j, k;
    • i = 2*w;
    • w = w+1;
    • }
    • void A (int x, int y) {
    • float i, j;
    • B(h);
    • i = 3;
    • }
    • void main() {
    • int a, b;
    • h = 5; a = 3; b = 2;
    • A(a, b);
    • B(h);
    • }
    • C uses static scoping. Say which identifiers (including variablesand function names) are visible in the bodies of each of the functions: main, A, B.

1

  • If C used dynamic scoping and the calling sequence is main callsB. Say which identifiers would be visible in B.
  • If C used dynamic scoping and the calling sequence is main callsA. Say which identifiers would be visible in A.
  • If C used dynamic scoping and the calling sequence is main callsA; A calls B. Say which identifiers would be visible in B.
  1. (3 points) Find some online material to learn C++’s namespace mechanism. Explain briefly how it works and its benefits.
  2. (3 points) During the execution of a Java program, can a variable be visible but not allocated? Can a variable be allocated but not visible? Explain your answers.

 

  • hw2_solutions.pdf