[Solved] CSE505 Assignment 2Higher-order Procedures

$25

File Name: CSE505_Assignment_2Higher-order_Procedures.zip
File Size: 395.64 KB

SKU: [Solved] CSE505 Assignment 2–Higher-order Procedures Category: Tag:
5/5 - (1 vote)
  1. This question is about static scoping, recursion, and higher-order procedures in the C programming language. Run the following C program through Gnu C compiler:

#include <stdio.h>

int main() { int x, y;

void p1(int y, void q(int)) { void p2(int x) { x = y + 2; printf(%d
, x); q(y);

}

if (x == y)

q(y); else p1(y+1, p2);

}

void p2(int x) { x = y + 2; printf(%d
, x);

}

x = 2; y = 2; p1(0, p2);

}

  1. What is the sequence of values printed?
  2. Draw a Scope Diagram at the point when the last value was just printed.
  3. Draw a Stack Diagram at the point when the last value was just printed.

Prepare your answers to parts a, b, and c in a file A2_problem1.pdf. Refer to Lecture 10 for Scope and Stack Diagrams as well as closures. Please note:

  1. In the Scope Diagram, for every call on p1, be sure to show the closure that is passed to q in addition to the value bound to y. It is important to correctly nest the frames for procedure calls.
  2. In the Stack Diagram, it suffices to show just the names of the stack frames along with the

static and dynamic links. Internal details of procedures p1 and p2 are not required.

Compiling and running a C program (say, program.c) using the Gnu C compiler under Linux:

  1. Compiling c: /util/bin/gcc program.c
  2. Executing c: ./a.out

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSE505 Assignment 2Higher-order Procedures
$25