PLP Question Bank For Reference Purpose
PLP Question Bank For Reference Purpose
NOTE: This Question Bank is only for reference purpose please do not depend totally on these
questions.
Study from the given syllabus and cover all the points.
1. What are the different factors that influences the evolution of programming languages?
Readability
Language constructs were designed more from the point of view of the computer than the users.
Because ease of maintenance is determined in large part by the readability of programs, readability
became an important measure of the quality of programs and programming languages. The result is a
crossover from focus on machine orientation to focus on human orientation. The most important
criterion “ease of use”
Writability
It is a measure of how easily a language can be used to create programs for a chosen problem domain.
Most of the language characteristics that affect readability also affect writability.
A smaller number of primitive constructs and a consistent set of rules for combining them is much better
than simply having a large number of primitives.
Abstraction means the ability to define and then use complicated structures or operations in ways that
allow many of the details to be ignored.
A process abstraction is the use of a subprogram to implement a sort algorithm that is required several
times in a program instead of replicating it in all places where it is needed.
Expressivity
It means that a language has relatively convenient, rather than cumbersome, ways of specifying
computations.
Type checking: is simply testing for type errors in a given program, either by the compiler or during
program execution.
The earlier errors are detected, the less expensive it is to make the required repairs. Java requires type
checking of nearly all variables and expressions at compile time.
Exception handling: the ability to intercept run-time errors, take corrective measures, and then continue
is a great aid to reliability.
Aliasing: it is having two or more distinct referencing methods, or names, for the same memory cell.
It is now widely accepted that aliasing is a dangerous feature in a language. Readability and writability:
Both readability and writability influence reliability.
Cost
Categories
Compiling programs
Executing programs
Maintaining programs: Maintenance costs can be as high as two to four times as much as development
costs.
Q 2. What are the different components of the context free grammar used for programming language
construction?
• a set of terminal symbols, which are the characters of the alphabet that appear in the strings
generated by the grammar.
• a set of nonterminal symbols, which are placeholders for patterns of terminal symbols that can be
generated by the nonterminal symbols.
• a set of productions, which are rules for replacing (or rewriting) nonterminal symbols (on the left side
of the production) in a string with other nonterminal or terminal symbols (on the right side of the
production).
• a start symbol, which is a special nonterminal symbol that appears in the initial string generated by the
grammar.
• Apply one of the productions with the start symbol on the left hand size, replacing the start symbol
with the right hand side of the production;
• Repeat the process of selecting nonterminal symbols in the string, and replacing them with the right
hand side of some corresponding production, until all nonterminals have been replaced by terminal
symbols.
Structure of Compiler: A compiler takes input as source program and produces as output an equivalence
sequence of machine instructions.
The compilation process is divided into a series of sub process called phases. A phase is a logically
cohesive operation that takes as input one representation of source program and produce as output i.e;
target program in other representation.
Phases of Compilation:
1. First Phase: lexical analyzer or scanner separate character of source language into a group of logically
belongs to each other. This group is called as tokens. The usual tokens are keywords such as do or if,
identifiers such as a or b, operator symbol as = + < > and punctuation symbol as () and comma. The
output is a stream of tokens pass to the rest of phases.
2. Second Phase: the syntax analyzer or parser group tokens together into syntactic structure for
example 3 tokens as A+B group together into syntactic structure as expression. Expression might further
be combined into statement. We form a tree who's leaf are tokens, an interior node represent string of
token that logically belong together. for example : the statement - if(5 equ max) goto 100 has 8 tokens.
3. Third Phase: intermediate code generator use the structure produced by syntax analyzer to create a
stream of simple instructions. Different style we are using like MACROS.
4. Fourth Phase: code optimization is an optional phase design to improve the intermediate code so that
object program run faster and take less space. Its output is also intermediate code but it saves time.
5. Fifth Phase: the final phase at code generation produce the object code by deciding on memory
location for data, selecting code and selecting register in which each computation done.
The table management or book keeping keeps track of the name and record and all the essential
information about each of the data type. The data structure which is used to record the information
called the symbol table.
Ans:
a) Character set : The choice of character set is one of the first to be made in designing language syntax.
The character set is nothing but group of characters which are allowed programming language including
special characters such as 'A', '\n'. n'. Each language may have its own character set or may language can
share same set.
b) Identifiers : Identifier is a string of letters & digits beginning with a letter. These are names that are
given to various program elements, such as variables, functions.
c) Operator Symbols Most languages use the special characters + and — to represent the two basic
arithmetic operations. Primitive operations may be represented entirely by special characters like APL.
1) Keyword : "A keyword is an identifier used as a fixed part of the syntax of a statement. Example 'if '
beginning a 'C' conditional statement. 'for' beginning a 'C' iterative statement.
e) Noise Words: Noise words are optional words that are inserted in statement to improve readability.
For example, in COBOL, the 'GO TO' statement transfer control within the program. It is written as, GO
TO label.
Where GO is required & TO is optional; it carries no information & is only used to improve readability.
J) Expressions:
k) Statement:
Q. : Define pointer. Explain various design issues of pointer and pointers in c/c++.
Ans :
Pointer is a variable that represents the location of a data item, such as variable or an array element.
Within the computer’s memory, every stored data item occupies one or more contiguous memory cells.
The number of memory cells required to store a data item depends on the type of the data item. For
example, a single character will typically be stored in one byte of memory; an integer usually requires
two contiguous bytes, a floating-point number usually requires four contiguous bytes, and a double
precision usually requires eight contiguous bytes.
Suppose v is a variable that represents some particular data item. The compiler will automatically assign
memory cells to this data item. The data item can then be accessed if we know the address of the first
memory cell. The address of v’s memory location can be determined by the expression &v, where & is
the unary operator, called the address operator, that evaluates the address of its operand.
Now let us assign the address of v to another variable pv. Thus pv = &v;
This new variable is called pointer to v. since it “points to” the location where v is stored in address, not
its value. Thus pv is referred to as a pointer variable. The relationship between pv and v is illustrated in
the following figure.
For example,
int i,*ptri;
float f,*ptrf;
The first line declares i to be an integer type variable and ptri to be a pointer variable whose object is an
integer quantity. The second line declares f to be a floating-point type variable and ptrf to be a pointer
variable whose object is a floating point quantity.
Within a variable declaration, a pointer variable can be initialized by assigning in the address of another
variable, remember that the variable whose address is assigned to the pointer variable must have been
declared earlier in the program, for example,
int i;
int *ptri=&i;
The first line declares i to be integer type variable and the second line declares ptri to be a pointer
variable whose object is an integer point quantity. In addition, the address of i is initially assigned to ptri.
Q. : Explain the problem caused by uniform evaluation rule while evaluating an expression and the
solution to the problem.
Ans The solution of the problem caused by uniform evaluation rule can be solved by associativity, the
associativity (or fixity) of an operator is a property that determines how operators of the same
precedence are grouped in the absence of parentheses. If an operand is both preceded and followed by
operators (for example, "^ 4 ^"), and those operators have equal precedence, then the operand may be
used as input to two different operations (i.e. the two operations indicated by the two operators). The
choice of which operations to apply the operand to, is determined by the "associativity" of the
operators. Operators may be associative (meaning the operations can be grouped arbitrarily), left-
associative (meaning the operations are grouped from the left), right-associative (meaning the
operations are grouped from the right) or non-associative (meaning operations cannot be chained, often
because the output type is incompatible with the input types). The associativity and precedence of an
operator is a part of the definition of the programming language; different programming languages may
have different associativity and precedence for the same type of operator.
Consider the expression a ~ b ~ c. If the operator ~ has left associativity, this expression would be
interpreted as (a ~ b) ~ c. If the operator has right associativity, the expression would be interpreted as a
~ (b ~ c). If the operator is non-associative, the expression might be a syntax error, or it might have some
special meaning. Some mathematical operators have inherent associativity. For example, subtraction
and division, as used in conventional math notation, are inherently left-associative. Addition and
multiplication, by contrast, have no inherent associativity, though most programming languages define
associativity for these operations as well.
Many programming language manuals provide a table of operator precedence and associativity; see, for
example, the table for C and C++.
The concept of notational associativity described here is related to, but different from the mathematical
associativity. An operation that is mathematically associative, by definition requires no notational
associativity. (For example, addition has the associative property, therefore it does not have to be either
left associative or right associative.) An operation that is not mathematically associative, however, must
be notationally left-, right-, or non-associative. (For example, subtraction does not have the associative
property, therefore it must have notational associativity.)
Ans
The control of execution of the operations, both primitive and user defined, is termed as sequence
control.
1. Expressions : These form the basic building blocks for statements and express how at are manipulated
and changed by a program. Properties such as precedence rules and parentheses determine how
expressions become evaluated.
2. Statement; : Statements such as conditional or iterative statements, determine how control flows
from one segment of a program to another.
3. Declarative programming: It is an execution model that does not depend on statements, but
nevertheless causes execution to proceed through a program.
4. Subprograms :Subprograms such as subprogram calls and coroutines, form a way to transfer control
from one segment of a program to another.
These are defined by language to be in effect ’un1es'smodified by the programmer through some
explicit structure. For example, most languages define the physical sequence of statements in a program
as controlling the sequence in which statements are executed, unless modified by an explicit sequence-
control statement.
These are the sequence-control structures that the programmer may optionally use to modify the
implicit sequence of operations defined by the language.
Q. : Explain the different categories of scalar type variables with their advantage and disadvantages.
Variables are identifiers used in a program to represent the different kinds of data. The variables holding
data of scalar data types are known as scalar variables. They are the most common ways of storing data.
The scalar variables are used to hold fundamental types of data in a program. Literals can also be used
to refer to data in a program. Based on the kind of data stored or represented, the variables or the
literals belong to the respective data type.
The scalar type variables are introduced in a program by means of declarations. A declaration is a
statement in a program that defines variables of a specific data type. A variable declaration statement
fixes the name and data type of the variables it defines. The type then restricts the set of possible values
which can be stored in the variables and also defines the memory requirements for storing actual
values. In Java such amount of memory is fixed for each type and known at compile time. Variables
declaration is essential for their use. If we do not declare variables they are not known to the compiler,
it is not able to check if they are used according to the restrictions of the type, they belong to. Hence, all
the variables must be declared prior to using them in a program. The format of declaring the scalar
variables is given below:
where,
varl, var2, varN represent variable names that are called declarators.
Q. : What is the difference between procedure and function? Explain with suitable example
Ans:
1. Procedure may or may not return value where as function should return one value.
2. Procedure can performs one or more tasks where as function performs a specific task.
4. We can call Stored Procedure within function but we can not call function within stored procedure.
5.A FUNCTION must be part of an executable statement, as it cannot be executed independently where
as procedure represents an independent executable statement.
5. Function can be called form SQL statement where as procedure can not be called from the SQL
statement.
6. Function are normally used for computation where as procedure are normally used for executing
business logic.
7. Stored procedure supports deferred name resolution where as function wont support.
8. Stored procedure returns always integer value by default zero. whrer as function returns type could
be scalar or table or table value. 10.Stored procedure is precompiled execution plan where as function
are not.
Q. : What do you mean by referencing environment of sub program? Discuss its several components ?
• Subprograms are generally allowed to define their own variables, thereby defining local referencing
environments. Variables that are defined inside subprograms are called local variables because access to
them is usually restricted to the subprogram in which they are defined.
• If local variables are stack dynamic, they are bound to storage when the subprogram begins execution
and unbound from storage when that execution terminates. An advantage of this is flexibility.
• Another advantage is that some of the storage for local variables of all subprograms can be shared
o Cost of time required to allocate, initialize and de-allocate for each activation
o Accesses of stack dynamic local variables must be indirect, where accesses to static can be direct
o Stack dynamic local variables, the subprograms cannot retain data values of local variables between
calls.
• The primary advantage of static local variables is that they are very efficient because of no indirection
Q. : Explain the following implementation models for parameter passing with an example.
i) Pass-By-value
ii) Pass-By-value-Result
iii) Pass-By-Reference
iv) Pass-By-Name
Pass-by-Value
When a parameter is passedby value, the value of the actual parameter is used to initialize the
corresponding formal parameter, which then acts as a local variable in the subprogram, thus
implementing in-mode semantics.
Pass-by-Result
Pass-by-Value-Result
Pass-by-value-result is an implementation model for inout-mode parameters in which actual values are
copied. It is in effect a combination of pass-by-valueand pass-by-result. The value of the actual
parameter is used to initialize the corresponding formal parameter, which then acts as a local variable.
In fact, pass-by-value-result formal parameters must have local storage associated with the called
subprogram. At subprogram termination, the value of the formal parameter is transmitted back to the
actual parameter. Pass-by-value-result is sometimes called pass-by-copy, because the actual parameter
is copied to the formal parameter at subprogram entry and then copied back at subprogram
termination.
Pass-by-Reference
Pass-by-Name :
In this method, the arguments to a function arc not evaluated before the function is called. Their
identifications arc substituted directly into the function body and then left to be evaluated whenever the
function encounters them. If an argument is not actually used in the function body that argument is
never evaluated and if it is used several times, it is re-evaluated each time it appears. This is one of the
most complex argument passing methods to implement. Effectively, each argument is as if represented
by its own evaluation function reference. In the language FORTH, the variables are passed in sonic what
similar fashion.
The major program and data elements requiring storage during program execution. Code segments for
translated user programs A major block of storage in any system must he allocated to store the code
segments representing the translated form of user programs, regardless of whether programs are
hardware- or software-interpreted. In the former case, programs are blocks of executable machine
code; in the latter case, blocks are in some intermediate form. System run-time programs Another
substantial block of storage during execution must be allocated to system programs that support the
execution of the user programs. These may range from simple library routines; such as sine, cosine, or
print-string functions, to software interpreters or translators present during execution. Also included
here are the routines that control run-time storage management. User-defined data structures and
constants. Space for user data must be allocated for all data structures declared in or created by user
programs including constants. Subprogram return points Subprograms may be invoked from different
points in a program.
ANS
Abstraction "Abstraction refers to the act of representing essential features without including
background details or explanations." The main idea behind data abstraction is to give a clear separation
between properties of data type and the associated impiementation details. This separation is achieved
in order that the properties of the abstract data type are visible to the user interface and the
implementation details are hidden. Thus, abstraction forms the basic platform for the creation of user-
defined data types called objects. Data abstraction is the process of refining data to its essential form. In
object-oriented programming language C++, it is possible to create and provide an interface that
accesses only certain elements of data types. The programmer can decide which user to give org rant
access to and hide the other details. This concept is called data a hiding which is similar in concept to
data abstraction. Example : When designing a class student in C++, we need the data elements such as
rotno, student_ name, marks, grade, etc. If we now design a class representing a cricket player we need
details like player_name, no_of centuries, striking ,rate, no_ofs matches played, etc. It will not make
sense to add the player's marks, grades which are applicable to a student class to this player class.
Encapsulation Encapsulation is the process of combining or packaging data with functions and thereby
The concept of abstraction brings forth another related term known as encapsulation. "The wrapping up
of data and functions that act upon that data in a single unit is termed as encapsulation". It binds
together both the data and code and thus keeps both safe from the outside world. The data and the
code to manipulate the data are combined in such a way that a black box is created which is self
contained and modular. This box is termed as a class in object oriented terminology. Within a class the
code or the data can be private or public. If it is private then these cannot be accessed by the outside
world whereas public means that the code and the data is accessible to everyone. Typically the data is
private and the methods are an interface to the private elements of the object. Thus, encapsulation
allows users to create a new data type. This new data type is termed abstract data type. Though the new
data type is similar to that of built-in data type, it is termed abstract data type because it enables users
to abstract a concept from the problem space into the solution space. Apart from the above, all the
features that hold for built-in types also hold solution space. Apart from the above, all the features that
hold for built-in types also hold for abstract data types. Data encapsulation led to the important concept
of data hiding. Data hiding is the implementation details of a led to the important concept of data
hiding. Data hiding is the implementation details of a Class that are hidden from the user. Class that are
hidden from the user.
return salary;
Q. : Explain Briefly:
i) Garbage collection
ii) Semaphores
Ans : i) Garbage collection (also known as GC) is a form of automatic memory management. The garbage
collector or collector attempts to reclaim garbage, or memory used by objects that will never again be
accessed or mutated by the application. Garbage collection is often portrayed as the opposite of manual
memory management, which requires the programmer to specify which objects to deallocate and return
to the memory system. However, many systems use a combination of the two approaches, and there
are other techniques being studied (such as region inference) to solve the same fundamental problem.
Note that there is an ambiguity of terms, as theory often uses the terms manual garbage-collection and
automatic garbage-collection rather than manual memory management and garbage-collection, and
does not restrict garbage-collection to memory management, rather considering that any logical or
physical resource may be garbage-collected.
Description
1. Determine what data objects in a program will not be accessed in the future
By making manual memory deallocation unnecessary (and typically impossible), garbage collection frees
the programmer from having to worry about releasing objects that are no longer needed, which can
otherwise consume a significant amount of design effort. It also aids programmers in their efforts to
make programs more stable, because it prevents several classes of runtime errors. For example, it
prevents dangling pointer errors, where a reference to a deallocated object is used.
ii) A semaphore is a protected variable whose value can be accessed and altered only by the operations
P and V and initialization operation called 'Semaphoiinitislize'.
Binary Semaphores can assume only the value 0 or the value 1 counting semaphores also called general
semaphores can assume only nonnegative values.
The P (or wait or sleep or down) operation on semaphores S, written as P(S) or wait (S), operates as
follows:
P(S): IF S > 0
THEN S := S - 1
ELSE (wait on S)
The V (or signal or wakeup or up) operation on semaphore S, written as V(S) or signal (S), operates as
follows:
ELSE S := S +1
Operations P and V are done as single, indivisible, atomic action. It is guaranteed that once a semaphore
operations has stared, no other process can access the semaphore until operation has completed.
Mutual exclusion on the semaphore, S, is enforced within P(S) and V(S).
If several processes attempt a P(S) simultaneously, only process will be allowed to proceed. The other
processes will be kept waiting, but the implementation of P and V guarantees that processes will not
suffer indefinite postponement.
ANS:
Concurrency refers to techniques that make program more usable. Concurrency can be implemented
and is used a lot on single processing units, nonetheless it may benefit from multiple processing units
with respect to speed. If an operating system is called a multi-tasking operating system, this is a
synonym for supporting concurrency. If you can load multiple documents simultaneously in the tabs of
your browser and you can still open menus and perform more actions, this is concurrency. On a single-
processor machine, the operating system’s support for
concurrency allows multiple applications to share resources in such a way that applications appear to
run at the same time. Since a typical application does not consume all resources at a given time, a
careful coordination can make each application run as if it owns the entire machine.
An analogy is juggling. While there are only two hands, each ball thinks that it is caught and tossed with
a pair of dedicated hands.
1. Of course, the most obvious benefit is to be able to run multiple applications at the same time.
2. Since resources that are unused by one application can be used for other applications, concurrency
allows better resource utilization.
3. Without concurrency, each application has to be run to completion before the next one can be run.
Therefore, concurrency allows a better average response time of individual applications.
4. Concurrency does not merely timeshare the computer; concurrency can actually achieve better
performance. For example, if one application uses only the processor, while another application uses
only the disk drive, the time to run both applications concurrently to completion will be shorter than the
time to run each application consecutively.
4. In extreme cases of running too many applications concurrently will lead to severely degraded
performance.
Ans:
• Predicate calculus gives the underpinnings to the languages of logic programming, such as Prolog.
• Predicate calculus is increasingly used for specifying the requirements of computer applications.
• In the area of proving program correctness, predicate calculus allows one to precisely state under
which conditions a program gives the correct output.
Function Declaration
A function declaration introduces a function or method into your program. A function declared in the
context of class, structure, enumeration, or protocol is referred to as a method. Function declarations
are declared using the keyword func and have the following form:
statements
If the function has a return type of Void, the return type can be omitted as follows:
statements
The type of each parameter must be included—it can’t be inferred. Although the parameters to a
function are constants by default, you can write let in front of a parameter’s name to emphasize this
behavior. Write var in front of a parameter’s name to make it a variable, scoping any changes made to
the variable just to the function body, or write inout to make those changes also apply to the argument
that was passed in the caller’s scope. For a discussion of in-out parameters, see In-Out Parameters.
Functions can return multiple values using a tuple type as the return type of the function.
A function definition can appear inside another function declaration. This kind of function is known as a
nested function. For a discussion of nested functions, see Nested Functions.
Function Declaration
A function declaration introduces a function or method into your program. A function declared in the
context of class, structure, enumeration, or protocol is referred to as a method. Function declarations
are declared using the keyword func and have the following form:
statements
If the function has a return type of Void, the return type can be omitted as follows:
func function name(parameters) {
statements
The type of each parameter must be included—it can’t be inferred. Although the parameters to a
function are constants by default, you can write let in front of a parameter’s name to emphasize this
behavior. Write var in front of a parameter’s name to make it a variable, scoping any changes made to
the variable just to the function body, or write inout to make those changes also apply to the argument
that was passed in the caller’s scope. For a discussion of in-out parameters, see In-Out Parameters.
Functions can return multiple values using a tuple type as the return type of the function.
A function definition can appear inside another function declaration. This kind of function is known as a
nested function. For a discussion of nested functions, see Nested Functions.
In general, an exception is handled (resolved) by saving the current state of execution in a predefined
place and switching the execution to a specific subroutine known as an exception handler. If exceptions
are continuable, the handler may later resume the execution at the original location using the saved
information.
For example, a floating point divide by zero exception will typically, by default, allow the program to be
resumed, while an out of memory condition might not be resolvable transparently. Alternative
approaches to exception handling in software are error checking, which maintains normal program flow
with later explicit checks for contingencies reported using special return values or some auxiliary global
variable such as C's errno or floating point status flags; or input validation to preemptively filter
exceptional cases.
Q Represent communication between client and server along with diagram. Differentiate between
Client-Side Scripting and Server Side Scripting language.
Q Write a program using java script to find out string staring with @ and ending with #. count the no of
occurrences of the same.
Q What are the different factors that influences the evolution of programming languages?
Q Explain the following implementation models for parameter passing with an example.
Pass-By-value
Pass-By-value-Result
Pass-By-Reference
Pass-By-Name
Q Select appropriate programming paradigm to write a program to calculate the area of shape. Circle
has data member radius and Rectangle has data member length and breadth. Both Circle and Rectangle
have function named area( ) to calculate area
Q What do you mean by referencing environment of sub program? Discuss its several components?
Q What is the difference between procedural programming paradigm and functional programming
paradigm? Which of the both follows lazy evaluation.
Q Write a Program to multiply each numbers from given list by 10 using lambda function.
Q State the different categories of scalar type variables with their advantage and disadvantages.
Q Write the output of the following program along with the explanation:
int x = 128;
(b)
(c) r = lambda g: g * 2
s = lambda g: g * 3
x=2
y= 3
x = r(x)
y = s(y)
print(x)
print(y)
(d)
char arr[7]="Network";
printf("%s", arr);
return 0;
Q What are the different components of the context free grammar used for programming language
construction?
Q For a Given grammar, construct an operator precedence relation matrix, assuming *, + are binary
operators and id as terminal Symbol and S, A, B as non-terminal symbol.
S →S+A/A
A→ A*B/B
C→A-B
B → id
Apply operator precedence parsing algorithm for the given input string
id + id * id
Q Consider the following grammar and eliminate left recursion-
S → (L) / a
L → L,S / S
S→A
A → Ad / Ae / aB / ac
B → bBc / f
Q Explain the problem caused by uniform evaluation rule while evaluating an expression and the
solution to the problem.
Q Create the knowledge base for the following and answer the give queries.
mack is a cat
max is a dog
Who is dog?
***********************************************************************************
NOTE: This Question Bank is only for reference purpose please do not depend totally on these
questions.
Study from the given syllabus and cover all the points.