PCPF DSE MOdel Answer Key
PCPF DSE MOdel Answer Key
Preprocessor
The source code is the code which is written in a text editor and the source code file is given an extension
".c". This source code is first passed to the preprocessor, and then the preprocessor expands this code.
After expanding the code, the expanded code is passed to the compiler.
Compiler
The code which is expanded by the preprocessor is passed to the compiler. The compiler converts this
code into assembly code. Or we can say that the C compiler converts the pre-processed code into
assembly code.
Assembler
The assembly code is converted into object code by using an assembler. The name of the object file
generated by the assembler is the same as the source file. The extension of the object file in DOS is '.obj,'
and in UNIX, the extension is 'o'. If the name of the source file is 'hello.c', then the name of the object file
would be 'hello.obj'.
Linker
Mainly, all the programs written in C use library functions. These library functions are pre-compiled, and
the object code of these library files is stored with '.lib' (or '.a') extension
References and values: If variables are references, then every object must be created explicitly, and it
is easy to ensure that an appropriate constructor is called. If variables are values, then object creation
can happen implicitly as a result ofelaboration. In this latter case, the language must either permit
objects to begin their lifetime uninitialized, or it must provide a way to choose an
appropriateconstructor for every elaborated object.
Execution order: When an object of a derived class is created in C++, the compiler guarantees that the
constructors for any base classes will be executed, outermost first, before the constructor for the derived
class. Moreover, if a classhas members that are themselves objects of some class, then the constructors
for the members will be called before the constructor for the object in which they are contained. These
rules are a source of considerable syntactic and semantic complexity: when combined with multiple
constructors, elaborated objects, and multiple inheritance, they can sometimes induce a complicated
sequence of nested constructor invocations, with overload resolution, before control even enters a given
scope. Other languages have simpler rules.
Garbage collection: Most object-oriented languages provide some sort of constructor mechanism.
Destructors are comparatively rare. Their principal purpose is to facilitate manual storage reclamation
in languages like C++. If the language implementation collects garbage automatically, then the need for
destructors is greatly reduced.
1. Client-side scripting :
Web browsers execute client-side scripting. It is used when browsers have all code.
Source code is used to transfer from webserver to user’s computer over the internet and
run directly on browsers. It is also used for validations and functionality for user events.
It allows for more interactivity. It usually performs several actions without going to the
user. It cannot be basically used to connect to databases on a web server. These scripts
cannot access the file system that resides in the web browser. Pages are altered on basis
of the user’s choice. It can also be used to create “cookies” that store data on the user’s
computer.
2. Server-side scripting :
Web servers are used to execute server-side scripting. They are basically used to create
dynamic pages. It can also access the file system residing at the webserver. A server-side
environment that runs on a scripting language is a web server.
Scripts can be written in any of a number of server-side scripting languages available. It
is used to retrieve and generate content for dynamic pages. It is used to require to
download plugins. In this load times are generally faster than client-side scripting. When
you need to store and retrieve information a database will be used to contain data. It can
use huge resources of the server. It reduces client-side computation overhead. The server
sends pages to the request of the user/client.
Q.2.
a) Define method Binding with its types.
Dynamic Method Binding in java
There are certain key points that are needed to be remembered before adhering forward where
we will be discussing and implementing static and dynamic bindings in Java later concluding
out the differences.
● private, final and static members (methods and variables) use static binding while for
virtual methods (In Java methods are virtual by default) binding is done during run
time based upon the run time object.
● The static binding uses Type information for binding while Dynamic binding uses
Objects to resolve to bind.
● Overloaded methods are resolved (deciding which method to be called when there
are multiple methods with the same name) using static binding while overridden
methods use dynamic binding, i.e, at run time.
Static Binding
The binding which can be resolved at compile time by the compiler is known as static or early
binding. The binding of all the static, private, and final methods is done at compile-time.
In Producer there are two synchronized methods putMessage() which will call form run() method of
Producer and add message in Vector whereas getMessage() extracts the message from the queue for the
consumer.
Using message passing simplifies the producer-consumer problem as they don’t have to reference each
other directly but only communicate via a queue.
c)
Explain Prolog list Append and Concatenation with example.
6
d) Differentiate between Imperative Programming and Declarative Programming.
3 There are at least two steps to There is only one step to get from source
get from source code to code to execution.
execution.
Q.3.
File Scope: These variables are usually declared outside of all of the functions and blocks, at the top of
the program and can be accessed from any portion of the program. These are also called the global scope
variables as they can be globally accessed.
Block Scope: A Block is a set of statements enclosed within left and right braces i.e. ‘{‘ and ‘}’
respectively. Blocks may be nested in C(a block may contain other blocks inside it). A variable declared
inside a block is accessible in the block and all inner blocks of that block, but not accessible outside the
block. Basically these are local to the blocks in which the variables are defined and are not accessible
outside.
Function Prototype Scope: These variables range includes within the function parameter list. The scope
of the these variables begins right after the declaration in the function prototype and runs to the end of the
declarations list. These scopes don’t include the function definition, but just the function prototype.
Function Scope: A Function scope begins at the opening of the function and ends with the closing of it.
Function scope is applicable to labels only. A label declared is used as a target to go to the statement and
both goto and label statement must be in the same function.
class Table{
for(int i=1;i<=5;i++){
System.out.println(n*i);
try{
Thread.sleep(400);
}catch(Exception e){System.out.println(e);}
}
}
Table t;
MyThread1(Table t){
this.t=t;
t.printTable(5);
Table t;
MyThread2(Table t){
this.t=t;
t.printTable(100);
}
public class TestSynchronization2{
t1.start();
t2.start();
Output:
10
15
20
25
100
200
300
400
500
Q.4.
a) What is Type Systems ? explain with types.
Dynamic Typing:
In Dynamic Typing, type checking is performed at runtime. For example, Python is a
dynamically typed language. It means that the type of a variable is allowed to change
over its lifetime. Other dynamically typed languages are -Perl, Ruby, PHP, Javascript etc
## simple function
def add(a, b):
return a + b
Static Typing:
Static Typing is opposite to Dynamic Typing. In Static Typing, type checking is
performed during compile time. It means that the type of a variable is known at compile
time. For some languages, the programmer must specify what type each variable is (e.g
C, C++, Java), other languages offer some form of type inference(e.g. Scala, Haskell).
With Static Typing, variables generally are not allowed to change types.
String a;
a = "Java is good";
Classification of Types
b) What is Unification? Explain its rules with examples.
In unification, one or more variables being given value to make the two call terms identical. This
process is called binding the variables to values. For example, Prolog can unify the terms cat(A),
and cat(mary) by binding variable A to atom mary that means we are giving the value mary to
variable A. Prolog can unify person(Kevin, dane) and person(L, S) by binding L and S to atom
kevin and dane, respectively.
The compound term has any kind of argument like variables, list, numbers, atoms, and
compound terms. The following example shows some typical unification:
parent(A, B, C)
parent(kevin, henry, 30)
It will succeed with A, B, and C variables bound to kevin, henry, and 30, respectively.
parent(kevin, B, 25)
parent(A, henry, 30)
The 25 cannot be unified with 30, so it will fail.
1. Pipes
2. Shared Memory
3. Message Queue
4. Direct Communication
5. Indirect Communication
6. Message Passing
7. FIFO
Pipe
Pipe is a unidirectional data channel in which data can be moved in only one direction at a time. For
standard input and output methods, we can use two such pipes to create two-way channels to send and
receive the data in two processes, i.e, in input and output. These are used in all POSIX(Portable Operating
System Interface) systems and various versions of Windows OS.
Shared Memory
Shared memory is a type of memory that can be used or accessed by multiple processes simultaneously.
This is done for a reason as processes can communicate with each other. That is why almost all POSIX
systems and Windows operating systems use shared memory.
Message Queue
Multiple processes can read-write the data to the message queue even without connecting. Messages are
stored in the queue till their recipient retrieves them back. Message queues are helpful for interprocess
communication and are also used by most operating systems.
Message Passing
It is a mechanism that processes synchronization and communicates with each other. But, using this
mechanism, the processes can communicate without the shared variables being restored.
Generally, the inter-process communication mechanism provides two operations that are as follows:
● send (message)
● received (message)
Direct Communication
Generally, a link is established between two communication processes in this type of communication.
However, only one link can exist in every pair of communicating processes.
Indirect Communication
When processes share a common mailbox then only indirect communication can be established. Here,
each pair of these processes shares multiple links of communication. The nature of these shared links
could be unidirectional or bi-directional.
FIFO
It is general communication between two unrelated processes. It is also considered full-duplex, which
means that one process can communicate with another and vice versa.
The key distinctions between scripting and programming are listed in the table below:
It does not require compiling the file and It requires to compile the file first.
running directly.
Users can easily write and use it. It can be difficult to use and write.