Princess Nourah Bint Abdul Rahman University
College of Computer and Information Sciences
Department of Computer Science
1444 (First Semester)
CS 430 – Programming Languages Concepts
Assignment 2 “individually”
Deadline Monday 26-9-2022
Student ID: 44 100 4567 Section: ------------------------------
-----------------------------------------, 1063
Student Name:
Q. No
0131 1 d
-------------------------------------------------------------------------------------------------
MAX Marks Marks Obtained Comments
Q1 3
Q2 3
Q3 4
Total 10
Question 1: Consider the following skeletal C program.
void fun1(void) {
int a, b, c;
// call another function
void fun2(void) {
int d, e, f;
// call another function
void fun3(void) {
int c, d, e;
// call another function
void main () {
int a, f, e;
// call another function
Given the following calling sequences and assuming that dynamic scoping is used, what
variables are visible during execution of the last function called? Include with each visible
variable the name of the function in which it was defined.
CS430
a. main calls fun2; fun2 calls fun3.
b. main calls fun3; fun3 calls fun2.
c. main calls fun1; fun1 calls fun2; fun2 calls fun3
funez defauc3 fans3
a c d e'of fun3 foffun2ld hidden
Question 2: Consider the following javaScript program:
[Link]
Main {
func; coffun3 d hidden
diex,ofy,
b f var aof
main f hidden
function sub1() {
d eoffun3 foffun2ld
c c var a, b, c; hidden
a boffant . c mainlaf
. hidden
. hidden
1
function sub2() {
var a, y, c;
. . .
2
}
}
function sub3() {
var a, x, w;
funcorably
. . . a b cinsubl x xglobalvariablecchidden
3
}
} end main
a y cinsub2 bin sub a chidden
List all the variables, along with the program units where they are declared, that are visible in the
bodies of sub1, sub2, and sub3, (Points 1, 2, and 3)variable
global Hcscoping
assuming static hiddenis used.
a x winsub3 y c globalvariable x hidden
2
CS430
Question 3. Given the following Java program
public class Example {
public static int count;
public static void main(String[] args) {
Counter counter= new Counter();
counter.Grade_function();
HashSet myset;
myset = singleton("element");
[Link](myset);
myset = singleton("another");
[Link](myset);
}
}
class Counter {
Counter();
void Grade_function() {
int grade1=3.5;
int grade2=5.3;
int total = 0;
String message;
total=grade1+grade2;
[Link]("count = " + ++count);
message = “The total of student grades “ + “ is “ + total;
[Link](message);
}
public static HashSet singleton(Object obj) {
HashSet set;
set = new HashSet();
[Link](obj);
return set;
}
List all static variables, stack-dynamic variables, explicit heap-dynamic variables, and
implicit heap-dynamic variables. new
new b
Static variable Stack Dynamic Explicit Heap Dynamic implicit Heap
Dynamic
t count Countemr misery counter message
grader grade
total image my c
obj gym
global memory location
3
CS430
delete
of Ctt Lew
C milloc
new
Java