Welcome





Monday, January 17, 2011

Tutorial # 1

1. What are scripting languages? Give examples.

Scripting languages are used to glue together subsystems written in other languages. They are interpreted at run-time. This means that every time you want to run the program, a separate program needs to read the code, interpret it, and then follow the instructions in the code. Hence these programs run slower.
Some examples are: AppleScript, JavaScript, Perl, Python, PHP, Smalltalk etc



2. What are copy and reference semantics? How are they available in C++ and Java?

In copy semantics, all components of the composite data type are copied when an object is assigned.
In reference semantics,only the starting address of the object is copied when an object is assigned.
Generally c++ follows copy semantics.Reference semantics can be implemented using pointers.For example,the copy semantics in c++ can be shown as:
struct emp
{
double empno;
float salary;
};
emp e1={01254,20000};
emp e2;
e2=e1; //copy semantics
Likewise reference semantics can be implemented as:
emp* pe1=new emp;
emp* pe2=new emp;
*pe1=e1;
pe2=pe1;
Generally, java follows reference semantics for objects and copy semantics for primitive values.
class emp
{
double empno;
double sal;
}
emp e1=new emp(01245,20000);
emp e2;
e2=e1; //reference semantics
However, copy semantics can also be implemented using clone() method.
emp e1=new emp(01245,20000);
emp e2;
e2=e1.clone();//copy semantics


3. What are storable values? List some storable values in Java.

The values which can be stored in single storage cell are called storable values. In general, all languages regard particular data types to be storable values by default.

In java, primitive values and pointers to objects are considered as storable values.
Objects themselves are not storable. But implicitly they are accessed by pointers.
Examples: int,byte,double etc


4. What are expression-oriented languages?

5. Why is a language that supports only static storage allocation limited?

6. What are the features of ALGOL family of languages?

7. Why does a C/C++ programmer enclose a union inside another structure?

In an ordinary union, only one data member can be referenced at a time. In order to make it a discriminated union, we need to provide tags..

enum btreePageTypeTag { NEXT, BTREE };// tags

struct btreePageType {
btreePageTypeTag tag; //tag used to check
union {
long next;
diskNodeType btree;
} u;
};


8. Why are recursive types not available in most languages? What concepts are used to define recursive types?

9. In many programming languages, strings are defined as arrays of characters. Compare the consequences when the array is static, dynamic and flexible. (Assignment, Comparison, Concatenation)

10. What are visibility and lifetime? What is the purpose of local, global and static variables? What are initialized values in C/C++ and Java?

11. Write the corresponding if else statements:
int a, b,c, d, e;
a?b:c;
a?b:c?d:e;
a?b?c:d:e;
a?b:c?d:e?;

Please post answers to these questions as comments for this post. They will be later integrated in it.

No comments:

Post a Comment