0% found this document useful (0 votes)
8 views6 pages

Week 5

The document contains answers to various programming and technical questions, focusing on C and C++ programming concepts, Unix system calls, database management systems, operating systems, SQL queries, and computer networks. Key topics include memory allocation, command-line arguments, file handling, operator overloading, and the Translation Lookaside Buffer. It also provides SQL queries for specific database operations and explains the concept of Service Access Points in networking.

Uploaded by

as0876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

Week 5

The document contains answers to various programming and technical questions, focusing on C and C++ programming concepts, Unix system calls, database management systems, operating systems, SQL queries, and computer networks. Key topics include memory allocation, command-line arguments, file handling, operator overloading, and the Translation Lookaside Buffer. It also provides SQL queries for specific database operations and explains the concept of Service Access Points in networking.

Uploaded by

as0876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Ashutosh Sharma

RA2211003011350
WEEK 5

ANSWERS

C PROGRAMMING

1. What is the use of randomize () and srand () function?

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.

2. How do I determine the amount of memory currently available for allocating?

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.

3. How does a C program come to know about command line arguments?

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

to read or to write the data?

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>

using namespace std;

class Box {

public:

double length;

double breadth;

double height;

Box(double l, double b, double h) : length(l), breadth(b), height(h) {}

virtual ostream& operator<<(ostream& os) const {

os << "Box [Length: " << length << ", Breadth: " << breadth << ", Height: " << height << "]";

return os;

}
};

class ColoredBox : public Box {

public:

string color;

ColoredBox(double l, double b, double h, string c) : Box(l, b, h), color(c) {}

virtual ostream& operator<<(ostream& os) const override {

os << "ColoredBox [Length: " << length << ", Breadth: " << breadth << ", Height: " << height << ",
Color: " << color << "]";
return os;

};

int main() {

Box box(3.0, 4.0, 5.0);

ColoredBox cBox(3.0, 4.0, 5.0, "Red");

cout << box << endl;

cout << cBox << endl;

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.

2. What is the output of the above code?

The both are different

TECHNICAL QUESTIONS

Data structures

1. Sorting is not possible by using which of the following methods?

(a) Insertion

(b) Selection

(c) Exchange

(d) Deletion.

ANS: D
2. A binary tree with 20 nodes has null -

A- 21

Unix

1. Discuss the mount and unmount system calls.

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.

2. How does the inode map to the data block of a file?

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

1. What is the Translation Lookaside Buffer (TLB)?

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

1. State true or false. != , <>, ^= all denote the same operation.

TRUE

2. What are the privileges that can be granted on a table by a user to others?

The privileges that can be granted on a table in SQL include:

SELECT: Allows reading data from the table.

INSERT: Allows inserting new rows into the table.

UPDATE: Allows updating existing rows in the table.

DELETE: Allows deleting rows from the table.

REFERENCES: Allows creating foreign keys that reference the table.

ALL: Grants all the privileges listed above.

3. SQL-QUERIES: write the SQL statements for the given queries.

Table 1 : STUDIES

PNAME (VARCHAR), SPLACE (VARCHAR), COURSE (VARCHAR), CCOST

(NUMBER)

Table 2 : SOFTWARE

PNAME (VARCHAR), TITLE (VARCHAR), DEVIN (VARCHAR), SCOST (NUMBER),

DCOST (NUMBER), SOLD (NUMBER)

Table 3 : PROGRAMMER

PNAME (VARCHAR), DOB (DATE), DOJ (DATE), SEX (CHAR), PROF1 (VARCHAR),

PROF2

(VARCHAR), SAL (NUMBER)


LEGEND :

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

WHERE COURSE = 'PGDCA';

2. What is the highest number of copies sold by a package?

SELECT MAX(SOLD) AS Highest_Copies_Sold

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.

You might also like