You are on page 1of 9

1.

Distinguish between imperative languages and declarative language

Imperative programming is like Declarative programming, is


giving detailed instructions to similar to just giving your
your friend on how to reach your actual address. Your friend
address from their current can then figure out how to
location. You tell them exactly get there
what to do and where to go.

Imperative is also known as


procedural languages.
2. Static and Dynamic binding:
• A binding is an association between two things, such as a name and the
thing it names.
Eg. The binding of a class name to a class.

• A binding is static if it first occurs before run time and remains


unchanged throughout program execution.

• A binding is dynamic if it first occurs during execution or can change


during execution of the program.

4. Compare Compiler time binding & Run time binding(Early & Late Binding
• Compile time or early binding- If binding occurs before
runtime and remains unchanged throughout the program
execution. Compiled languages tend to have early binding times
The time when a single compilation unit is compiled, while
compiling the type of a variable can be identified. Example:
int c; [at compile time int, c forms an association]

• Run time or Late binding- If binding occurs during runtime or can change
during program execution. Interpreted languages tend to have later binding
times.
• Run time is a very broad term that covers the entire span
from the beginning to the end of execution. If we give the
value of a variable during runtime, it is known as runtime
binding

Note: Early binding--> Greater efficiency, Ease of implementation


Late binding--> Greater flexibility

5. What is JVM
JVM also known as Java virtual machine enables a computer to run Java programs as well as
programs written in other languages that are also compiled to Java bytecode.
6.Explain different types of programming paradigms

1) Imperative programming languages- It is also known as procedural


languages. An imperative language uses a sequence of statements to determine how
to reach a certain goal. Means here you will get the answer how to do a task not
what to do. For example, in C

int a = 4;

int b = 5;

int sum = 0;

sum = a + b;

From assigning values to each variable to the final addition of those values, each statement
changes the state of the program. Using a sequence of five statements the program shows
how to add the numbers 4 and 15. Example of Imperative language is: C, C++

2) Functional programming languages- It is also known as applicative


languages.
• Functional programming is a form of declarative programming
(mathematical function). Programming consists of building the function
that computes the answer.

There are two types:


• Pure Functional languages: It supports only functional paradigm. Ex.
Haskell.
• Impure Functional languages: It supports both functional and
imperative paradigm. Ex. Lisp. Example of Functional language is: Lisp,
Python, Haskell.

3) Logic programming languages-

This type of languages concentrates on what is the expected outcome for the program instead
of how the outcome is achieved.
• Logical programming is something like math.
• Logic program statements express facts and rules about problems.
• example, “A is true if B and C is true”.And to understand facts we can say that “A is
true”. Example of Logic language is: Prolog.
4) Object-oriented programming languages- Object oriented
programming language based on object instead of just functions and
procedures.
It involves concepts of oops programming languages. For example:
C++, Java.

7.What is dangling reference.

A dangling reference is a reference to an object that no longer exists.


Dangling reference arise during object destruction, when an object that has an
incoming reference is deleted or deallocated, without modifying the value of
the pointer, so that the pointer still points to the memory location of the
deallocated memory.
e.g., a pointer refers to an object that has already been deleted

•In languages with manual memory management, like C or C++, can encounter
dangling pointers, by doing this for instance:
int * p = new int;
delete p;
int i = *p; // error, p has been deleted

8.What is binding time.


Binding Time is the point at which a binding is created or, more generally, the
point at which any implementation decision is made language design time-
program structure, possible type, built-in features such as keywords.
• language implementation time
• I/O, arithmetic overflow, type equality (if unspecified in manual)
• implementation dependent semantics such as bit width of an integer
9.What is scope.

• Scope of a variable is the range of statements in which the variable is


visible
• The textual region of the program in which a binding is active is its
scope.
• A var is visible in a statement if it can be referenced in that statement.
• Local var is local in a program unit or block if it is declared there.
• Non-local var of a program unit or block are those that are visible within
the program unit or block but are not declared there

• Scope rules of a language determine how a particular occurrence of a


name is associated with a variable
Static scoping:
• It allows us to determine the use of every variable in a program statically,
without executing it at compile time.
• In static scope rules the bindings are defined by the physical (lexical)
structure of the program.

Dynamic scoping :
• With dynamic scope rules, bindings depend on the current state of
program execution
• The idea is to search for a name in a chain of called procedures, starting
from the main program.
• This chain is built according to the visibility rules

Static scope rules-


In a language with static(lexical) scoping, the bindings between names and
objects can be determined at compile time by examining the text of the
program, without consideration of the flow of control at run time.

Dynamic scope rules?


11. What is lifetime?

The period from creation to destruction is called the LIFETIME of a binding.

Lifetime of a variable: Time during the variable is bound to a specific


memory location.

12.Explain following terms-


13.Differenciate between compiler & interpreter

14 .List different imperative languages


Fortran, C#, Java, C, and C++ are examples of imperative programming.
15.List different declarative languages.
HTML, SQL, CSS and XML ++ are examples of declarative programming.

16. Explain following


• Static Allocation is appropriate when the storage requirements are
known at compile time.
• Static storage allocation is appropriate when the storage
requirements are known at compile time.
Examples:
- code in languages without dynamic compilation
- all variables in FORTRAN IV
- global variables in C, Ada, Algol
- constants in C, Ada, Algol
Advantages:
• Efficiency: All addressing of static can be direct.
•No run-time overhead is incurred for allocating and deallocating variables .
• History-sensitive: variables retain their values between separate executions
Disadvantage:
Storage cannot be shared among variables.
• Ex: if two large arrays are used by two subprograms, which are never active at
the same time, they cannot share the same storage
17.What is being printed in following code assuming dynamic Scope
& Static scope

(Maybe)

You might also like