Worksheet
Worksheet
C-Programming
Q1)
#include <stdio.h>
printf("%s\n", envp[i]);
return 0;
Q2)
The div() function in C is used to perform integer division and return both the quotient and
remainder in a single operation. It is defined in the stdlib.h header.
#include <stdio.h>
#include <stdlib.h>
int main() {
return 0;
Q3)
#include <stdio.h>
int main() {
&year);
return 0;
Q4)
#include <stdio.h>
int main() {
return 0;
}
Q5)
In C, you can dynamically allocate memory for an array using the malloc(), calloc(), or
realloc() functions from the stdlib.h library. Dynamic memory allocation allows you to
allocate memory at runtime, giving flexibility when the size of the array isn't known
beforehand.
C++ Programming
Q1)
#include <iostream>
class Date {
private:
public:
{ day = d;
month = m;
year = y;
cout << "Date: " << (day < 10 ? "0" : "") << day << "-"
}
};
int main() {
Date today;
today.setDate(26, 2, 2025);
today.displayDate();
return 0;
Q2)
The this pointer cannot be used inside a static member function in C++. The this pointer
refers to the current object of a class. However, static member functions belong to the class
itself rather than any particular object. As a result, static functions can be called without
creating an instance of the class. Since there is no object associated with the call, the this
pointer does not exist in the context of a static function. Consequently, attempting to use
this inside a static member function will result in a compilation error. Static functions can
only access static data members and other static functions directly. To access non-static
members, an explicit object reference is required.
DATA STRUCTURES
Q1)
Inorder Output:
HDBEAFCIGJ
Preorder Output:
ABDHECFGIJ
Postorder Output:
HDEBFIJGCA
Unix
Q1)
1. New (Created) – The process is being created but has not started execution yet.
2. Ready – The process is waiting in the queue for CPU time to execute.
When you run a program (e.g., by typing ./a.out in the terminal), the following steps occur:
1. Fork: The shell creates a child process using the fork() system call.
2. Exec: The child process replaces itself with the new program using exec(), loading
the executable into memory.
3. Process Scheduling: The OS schedules the process for execution, allocating CPU time.
4. Execution: The program runs and interacts with system resources (files,
memory, etc.).
5. Completion: Once finished, the process exits (exit()) and becomes a zombie until
the parent collects its exit status.
DBMS
Q1)
A Data Dictionary (or Data Directory) is a repository of metadata (data about data) in a
database. It stores information about database objects such as tables, columns, data types,
constraints, indexes, users, and relationships.
Operating System
Q1)
Page replacement occurs when a process needs a page that is not in memory, and the
system selects a page to remove.
Local Page Replacement
o
The process replaces pages from its allocated memory only.
o
Each process has a fixed number of frames, and it cannot take memory
from other processes.
o
Example: Fixed Allocation – If a process has 5 frames, it can only
replace pages within those 5 frames.
Global Page Replacement
o
The process can replace any page in memory, even from another process.
o
It improves system performance but may cause starvation (some
processes may keep losing pages).
o
Example: LRU (Least Recently Used), FIFO (First In First Out) – The
system selects a page from all available frames, not just the current
process’s allocated memory.
Q2)
Seek Time:
o
Time taken by the disk’s read/write head to move to the required
track (cylinder).
o
Most time-consuming part of disk access.
o
Example: If data is on track 40 but the head is at track 10, it takes time
to move to track 40.
Latency (Rotational Latency):
o
Time taken by the disk to rotate the required sector under the
read/write head.
o
Depends on disk RPM (Rotations Per Minute).
o
Example: The sector might be at the other end of the disk, so it takes time
to rotate to the correct position.
Transfer Time:
o
Time required to transfer data from the disk to memory once the head is
at the right position.
o
Example: Once the sector is under the head, the time taken to read and
send it to RAM.
Q3)
Paging is a memory management technique where the OS divides process memory into
fixed-sized pages and physical memory into fixed-sized frames.
Why use Paging?
o
Eliminates external fragmentation (unused memory between
allocated spaces).
o
Allows non-contiguous memory allocation (pages of a process can
be anywhere in RAM).
How Paging Works?
SQL
Q1)
2. Retrieves the COMM (Commission) column but uses NVL(COMM, 0), which
replaces any NULL values in COMM with 0.
3. Adds the Salary (SAL) and the Commission (COMM) to compute the total earnings
for each employee.
Q2)
The DATEDIFF() function is used in SQL to find the difference between two dates. SELECT
1. Display the details of packages for which the development cost has been
recovered. SELECT *
FROM SOFTWARE
FROM SOFTWARE
Computer Networks
Q1)
As a data packet moves from the upper to lower layers in the OSI (Open Systems
Interconnection) model, the following process occurs:
Encapsulation Process:
Each layer adds its own header (and sometimes trailer) to the data received from the layer
above before passing it down to the next layer.
Step-by-step process:
Q2)
· Connection Type
TCP (Transmission Control Protocol) is a connection-oriented protocol, meaning
it establishes a reliable connection before data transfer begins.
UDP (User Datagram Protocol) is connectionless, meaning data is sent
without setting up a dedicated connection.
· Reliability
TCP is reliable as it ensures data is delivered correctly and in order. It retransmits
lost packets and waits for acknowledgments.
UDP is unreliable since it does not guarantee data delivery, order, or
retransmission of lost packets.
· Error Checking
TCP performs extensive error checking, acknowledgments, and retransmission
to ensure data integrity.
UDP has minimal error checking and does not request retransmission if data is lost.
· Speed
TCP is slower due to its reliability mechanisms, such as error
checking, acknowledgments, and congestion control.
UDP is faster since it does not wait for acknowledgments or retransmit lost packets.
· Order of Data
TCP ensures data arrives in the correct order using sequence numbers.
UDP does not guarantee the order of data arrival, as packets may arrive out
of sequence.
· Usage
TCP is used for applications where data integrity and reliability are important, such
as web browsing (HTTP/HTTPS), file transfer (FTP), and email (SMTP).
UDP is used in applications where speed is more important than reliability, such
as video streaming, VoIP, gaming, and real-time communication.
· Header Size
TCP has a larger header (20-60 bytes) due to extra information for reliability and
flow control.
UDP has a smaller header (8 bytes), making it more efficient for quick
data transmission.
· Flow Control
TCP supports flow control and congestion control, which helps manage
network traffic and prevent packet loss.
UDP does not have flow control, making it more suitable for high-speed applications.
#include <iostream>
#include <vector>
{ int n = arr.size();
{ lis[i] = lis[j] + 1;
return maxLength;
}
int main()
{ int n;
cin >> n;
vector<int> arr(n);
return 0;
Q2)
#include <iostream>
void printPattern(int n)
{ int totalRows = 2 * n -
1; char letters[n];
{ letters[i] = 'a' + i;
int main()
{ int n;
cin >> n;
printPattern(n);
return 0;