Week 5
Week 5
RA2211003011350
WEEK 5
ANSWERS
C PROGRAMMING
randomize(): This function is generally used to seed the random number generator with a value that
can produce more random results
srand(): In C, srand() is used to set the seed for the rand() function, which generates pseudo-random
numbers. By calling srand() with a specific seed (often the current time), you can ensure that the
sequence of random numbers generated by rand() varies each time the program runs.
For general dynamic memory allocation, the malloc() function may fail if there is not enough
memory, which is usually detected by checking if it returns NULL.
In C, command-line arguments are passed to the program through the main() function.
4. When we open a file, how do functions like fread( )/fwrite(), etc. get to know from where
When a file is opened using functions like fopen() or freopen(), the file pointer is automatically set to
the beginning of the file (or another position if specified). fread() and fwrite() use the current file
pointer (managed internally by the file handling functions) to determine where to read from or write
to in the file. This file pointer keeps track of the current position within the file, and each function
call moves the pointer forward after reading or writing data
5. The sizeof( ) function doesn't return the size of the block of memory pointed to by a pointer.
Why?
The sizeof() operator in C determines the size of the type of the pointer, not the size of the memory
block it points to. When you use sizeof(pointer), it gives you the size of the pointer itself (typically 4
or 8 bytes depending on the architecture), not the size of the memory allocated or the data it points
to.
C++ PROGRAMMING
1. Write a C++ program to demonstrate the overloading of the << operator as a member
function in a class. Show how it can be virtual and overridden in derived classes. Provide an
explanation of how overloading as a virtual member differs from global friend functions.
#include <iostream>
class Box {
public:
double length;
double breadth;
double height;
os << "Box [Length: " << length << ", Breadth: " << breadth << ", Height: " << height << "]";
return os;
}
};
public:
string color;
os << "ColoredBox [Length: " << length << ", Breadth: " << breadth << ", Height: " << height << ",
Color: " << color << "]";
return os;
};
int main() {
return 0;
This example demonstrates the overloading of the << operator as a member function in a class
hierarchy. The base class Box has a member function operator<<, which prints the dimensions of the
box. The derived class ColoredBox overrides this operator to also include the color attribute. When
operator<< is used, the correct version (base or derived) is called based on the actual object type,
showing polymorphism in action. The use of virtual member functions allows overriding in derived
classes, while global friend functions would be limited to a single function that can't be overridden in
derived classes.
TECHNICAL QUESTIONS
Data structures
(a) Insertion
(b) Selection
(c) Exchange
(d) Deletion.
ANS: D
2. A binary tree with 20 nodes has null -
A- 21
Unix
Mount: The mount system call is used to attach a file system (usually stored on a disk) to a specific
point in the file system hierarchy (known as the mount point). When a file system is mounted, the
kernel makes it accessible for reading and writing under the specified directory.
Unmount: The umount system call is used to detach a file system from the file system hierarchy. This
is done to safely remove or disconnect a file system, making sure all data is flushed and no more
operations can be performed on it until it’s remounted.
An inode (index node) is a data structure that contains metadata about a file, such as its size,
permissions, owner, and pointers to the actual data blocks on disk. The inode maps to data blocks by
holding pointers (addresses) to the disk blocks that store the actual contents of the file. There are
direct pointers, indirect pointers, and sometimes doubly or triply indirect pointers, depending on the
file system’s structure and the file’s size.
DBMS
1. what is a relation?
A relation in a database management system (DBMS) refers to a table that consists of a set of tuples
(rows), with each tuple representing a data entry and each attribute (column) representing a specific
data field. Relations form the core of relational databases.
2. what is a table?
A table in a DBMS is a collection of data organized into rows and columns. Each row in a table
represents a record, and each column represents an attribute or field. Essentially, a table is the
implementation of a relation in the database.
Operating system
The Translation Lookaside Buffer (TLB) is a small, fast memory cache used by the Memory
Management Unit (MMU) to improve virtual address translation. When a program accesses memory,
the MMU must translate virtual memory addresses to physical memory addresses. The TLB stores
recent virtual-to-physical address mappings, allowing the MMU to quickly retrieve them instead of
having to access slower page tables in main memory.
2. What is the resident set and working set of a process?
Resident Set: The resident set of a process refers to the portion of the process's memory that is
currently held in physical RAM. This includes the code, data, and stack sections of the process that
have been loaded into memory for execution. The size of the resident set can change over time as
the operating system swaps pages in and out of memory.
Working Set: The working set of a process refers to the set of pages (or memory regions) that a
process is actively using during a given period of time. It represents the subset of the resident set
that is actively being referenced by the process. The working set can change dynamically as the
program executes and accesses different parts of memory.
SQL
TRUE
2. What are the privileges that can be granted on a table by a user to others?
Table 1 : STUDIES
(NUMBER)
Table 2 : SOFTWARE
Table 3 : PROGRAMMER
PNAME (VARCHAR), DOB (DATE), DOJ (DATE), SEX (CHAR), PROF1 (VARCHAR),
PROF2
PNAME - Programmer Name, SPLACE - Study Place, CCOST - Course Cost, DEVIN -
Developed in, SCOST - Software Cost, DCOST - Development Cost, PROF1 - Proficiency
1. Display the names of those who have done the PGDCA course.
SELECT PNAME
FROM STUDIES
FROM SOFTWARE;
COMPUTER NETWORKS
1. What is SAP?
Service Access Point (SAP) is a logical point used for communication between layers in the OSI
model. It serves as an interface between the upper and lower layers of the protocol stack,
enabling data to flow between different network services. For example, in the Data Link Layer,
SAPs identify the protocols used by the network, such as Ethernet or ARP, while in the Network
Layer, they help route data to specific protocols like IP or IPX. SAPs ensure that each layer can
pass data to the appropriate layer above or below it, ensuring seamless communication across
the network. Essentially, a SAP functions as a "doorway" or endpoint for different services in a
network protocol stack.