You are on page 1of 3

Programming Languages

Assignment 1
Deadline: Sunday 13 December 2020
Note: You have to submit the assignment either in .docx or .pfd format. In case of plagiarism
you will be award zero.
Problem 1: Answer the following short questions. 15 Marks. [CLO 1]
1. In C++, C# and Java, how long a variable name can be?
2. What is type inference? give an example.
3. What is the life time and scope of a variable? Explain with example.
4. What is the general problem with static scoping?
5. What are advantages and disadvantages of dynamic type binding?
6. After language design and implementation, what are the four time bindings can take place in a
program.
7. How the reference to a nonlocal variable in static –scoped program connected to its definition.
8. What is static ancestor and dynamic ancestor of a subprogram?

Problem 2: Answer the following question briefly. 15 Marks. [CLO 3]


1. Write a simple assignment statement with one arithmetic operator in Java. For each of the
component of the statement, list the various bindings that are required when statement is
executed.
2. Describe the situation when dynamic scoping makes a program difficult to read.
3. Consider the following JavaScript skeletal program

//The main program

var x;
function sub1()
{
var x;
function sub2()
{
.......
}
}
function sub3()
{
.......
}
Assume that the execution of the program is in the following unit order
main call sub1
sub1 call sub2
sub2 call sub3
a) Assume the static scoping, in the following, which declaration of the x is corrected one for
a reference to x?
i. Sub1
ii. Sub2
iii. Sub3

b) Repeat part a but assume dynamic scoping.

4. Consider the following skeletal C program:

void fun1 (void);


void fun2 (void);
void fun3 (void);

void main()
{
int a,b,c ;
....
}
void fun1(void)
{
int b,c,d ;
....
}
void fun2(void)
{
int c,d,e ;
....
}
void fun3(void)
{
int d,e,f ;
....
}

Given the following calling sequences and assuming that the dynamic scoping is used, what
variable are visible during the execution of the last function called.
i. Main calls fun1; fun1 calls fun2; fun2 calls fun3;
ii. Main calls fun3; fun3 calls fun2; fun2 calls fun1;
5. Write three functions in C++: one that declares a large array statically, one that declares the
same large array on the stack, and one that creates the same large array from the heap. Call
each of the subprogram a large number of times (at least 100,000) and output the time required
by each. Explain the results.

You might also like