PPL Q&a

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

PPL QUESTION ANWERS INTERNAL

1) Write a difference between call by value and call by reference.


 Call by Value is acopy of the data is sent to the function.
Effect: The original data stays the same. Changes only affect the copy.
 Call by Reference is areference to the original data is sent to the function.
Effect: The original data can be changed. Changes affect the original.
 Call by value keeps the original safe, while call by reference lets you modify it
directly.

2) What is formal parameter? Give example.


 A formal parameter is a dummy variable listed in the subprogram header and
used in the subprogram.

3) What is dynamic memory allocation?


 Dynamic memory allocation is a way to request memory while your program is
running. This is helpful when you don’t know how much memory you will need in
advance.

4) Which function is used to join two strings. Give Syntax.


 To join two strings, you can use the strcat function in C, and the + operator in
Python
 result = str1 + str2 in python + operator

5) Give difference between structure & union.

6) Explain malloc( ) and calloc( ) functions with example.


 malloc() stands for "memory allocation." It allocates a specified number of bytes
in memory and returns a pointer to the beginning of the allocated memory.
 calloc() stands for "contiguous allocation." It allocates memory for an array of
elements and initializes all bytes to zero.
7) What is an array slice? name any two languages supporting it.
 A slice is some substructure of an array. Slices are only useful in languages that
have array operations like python and java script

8) What is the difference between compiler and preprocessor.

9) Define union and free union.

10) Explain two solutions to dangling pointers.

 Set Pointers to NULL= After freeing memory, set the pointer to NULL
 In C++, use smart pointers like std::unique_ptr or std::shared_ptr
 Use Ownership Semantics- Design your program to have clear ownership of
resources.

11) What is deep and shallow binding.

 Shallow binding means a function uses the most recent value of a variable when
it's called.
 Deep binding means a function remembers the value of a variable from when it
was created, not when it's called.
12) Define the term “Constructor”.
 A constructor is a special method in a class that is automatically called when you
create an object (an instance) of that class. Its main job is to set up the initial values
of the object's properties.

13) Define the following terms.

 Precedence: is the rule that determines the order in which different operations (like
addition or multiplication) are performed in an expression.
 Associativity: Associativity is the rule that determines the order in which operators of
the same precedence are evaluated in an expression. It tells you how to group
operations when they are next to each other.
 Orthogonality: in programming languages means that different features work
independently of each other. You can use them together without causing
unexpected problems.
 String
 Binding: is how we connect names (like variables and functions) to their values or
actions in programming. It tells the computer what a name refers to.

14) Explain different types of operators available in C.

 Arithmetic Operators These operators perform basic mathematical


operations. Addition: + (e.g., a + b)
 Relational Operators These operators compare two values and return either true (1) or
false (0). Equal to: == (e.g., a == b)
 Logical Operators These operators are used to combine multiple conditions. Logical
AND: && (e.g., a && b)
 Bitwise Operators These operators perform operations on bits. Bitwise AND: & (e.g., a
& b)
 Assignment Operators These operators assign values to variables.
Simple Assignment: = (e.g., a = b)

15) Briefly explain data encapsulation and data abstraction.


Example encapsulation:
class Employee {
private:
int salary;
public:
void setSalary(int s) {
salary = s;
}
int getSalary() {
return salary;
}
};

17) Find out the output of following code. Justify. [5 marks]


main( )
{ int a = 10, b = 20;
{
int c = 30;
printf (“%d %d %d”, a, b, c);
}
printf (“%d %d %d”, a, b, c);
}
 The output of the first printf() is 10 20 30.
 The second printf() results in an error because c is not in scope, leading to a failure to
compile the program.

18) What is enumeration type? Give design issues for enumeration type.


19) Explain implementation of Single Inheritance with suitable example.

 The inheritance in which a single derived class is inherited from a single base class is
known as the Single Inheritance


 Simple Example: Animals
Imagine we have a general class called Animal, and a specific class called Dog that
inherits from Animal.

20) What is Binding Time? Explain the different binding times at which binding
decisions can be made.

 A binding is an association, such as between an operation and a symbol.


 Binding time is the time at which a binding takes place.
 Possible Binding Times
- Language design time -- bind operator symbols to operations
– Language implementation time-- bind floating point type to a representation
– Compile time -- bind a variable to a type in C or Java
– Load time -- bind a FORTRAN 77 variable to a memory cell (or a C static variable)
– Runtime -- bind a nonstatic local variable to a memory cell

10) What is short-circuited evaluation. Explain working with an example.

 Result is determined without evaluating all of the operands and/or operators


 Example: (13*a) * (b/13–1) If a is zero, there is no need to evaluate (b/13-1) – Usually
used for logical operators
 Problem with non-short-circuit evaluation:
When index=length, LIST [index] will cause an indexing problem (assuming LIST has
length -1 elements)

You might also like