0% found this document useful (0 votes)
2 views

Week 7_Assignment

Uploaded by

Aayush Bhure
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)
2 views

Week 7_Assignment

Uploaded by

Aayush Bhure
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/ 10

Week 7

C Programming

1. If we have declared an array as global in one file and we are using it in another file then why
doesn't the sizeof operator works on an extern array?

Ans: When you declare an array as extern in a file, you're only declaring a reference to the array, not
defining it. The compiler has no information about its size at the point of the sizeof operation. The sizeof
operator only works with the actual definition of an array because it needs the size at compile time..

2. How do I write printf() so that the width of a field can be specified at runtime?

Ans: You can use the * specifier in printf() to specify the field width dynamically at runtime.

Example:

#include <stdio.h>

int main() {

int width = 10;

printf("%*s\n", width, "Hello"); // Outputs " Hello" (5 spaces before "Hello")

return 0;

Here, the width is determined by the value of width.

3. How to find the row and column dimension of a given 2-D array?

Ans: The dimensions of a 2-D array can only be determined if you have access to its declaration. You
cannot determine them at runtime using the array pointer because it decays to a pointer when passed to a
function.

Example:
#include <stdio.h>

#define ROWS 3

#define COLS 4

void printDimensions(int arr[][COLS])

{ printf("Rows: %d\n", ROWS);

printf("Columns: %d\n", COLS);

int main() {

int arr[ROWS][COLS];

printDimensions(arr);

return 0;

4. Write a program to demonstrate the access() function.

Ans: The access() function is used to check the accessibility of a file. It is defined in <unistd.h>.

Example:

#include <stdio.h>

#include <unistd.h>

int main() {

const char *filename = "test.txt";


if (access(filename, F_OK) == 0)

{ printf("File exists.\n");

if (access(filename, R_OK) == 0)

printf("File is readable.\n");

else

printf("File is not readable.\n");

if (access(filename, W_OK) == 0)

printf("File is writable.\n");

else

printf("File is not writable.\n");

} else {

printf("File does not exist.\n");

return 0;

5. How do I convert a floating-point number to a string?

Ans: You can use sprintf() or functions like gcvt() or snprintf() to convert a float to a string.
Example using sprintf():

#include <stdio.h>

int main() {

float num = 123.456;

char str[20];

sprintf(str, "%f", num); // Convert float to string

printf("String: %s\n", str);

return 0;

C++ Programming

1. Expected Output and its Explanation.

Answer: Output:

a = 10, pa = 10, ra = 10

This output confirms that:

- a holds the value 10.


- The pointer pa correctly points to a, so *pa gives 10.
- The reference ra correctly references a, so ra also gives 10.
..

Answer:
The loop iterates 3 times, and each iteration calls deri::out(). Therefore, the output is:
- deri deri deri

Technical Questions

Data Structures

1. List out few of the Application of tree data-structure?


Ans: Binary Search Trees (BSTs): Used in database indexing and searching algorithms.

AVL Trees: Self-balancing BSTs used in dynamic sets and dictionaries.

Heap Trees: Used for priority queues and heap sort.

Trie: Used for efficient string matching, such as in autocomplete features.

Expression Trees: Used in compilers for parsing expressions.

Segment Trees: Used for range queries and updates.

B-Trees: Used in file systems and databases for organizing large blocks of data.

2: Applications of Multilinked Structures:


Ans: Social Networks: Representing relationships between people as
multilinked nodes.

Computer Networks: For routing information across multiple paths.

3D Modeling and Graphics: Storing vertex, edge, and face data.

Multiway Trees: Representing hierarchical data structures with multiple


parent-child relationships.

Sparse Matrices: Efficient storage of large, sparse data in linked


structures.

Unix

1: Explain System Call:

Ans: A system call is a mechanism used by a program to request services from the operating system's
kernel.

Example: open(), read(), write(), fork(), etc.

It acts as an interface between user space and kernel space.

2: Predict the Output of the Following Program:

Ans: Hello World

Hello World

DBMS

1: What is Tuple?
Ans: A tuple is a single row of data in a table, representing a single record.

2:What is a Selection?
Ans: Selection is a relational algebra operation used to filter rows in a table based on a specified condition.

Example: SELECT * FROM Employee WHERE Salary > 50000;


Operating System

1:What is Arm-Stickiness
Ans: Arm-stickiness refers to a situation in disk scheduling algorithms like SCAN or LOOK where the
disk arm tends to "stick" or stay on one side of the disk, repeatedly servicing requests in a certain region
due to constant new requests in that area

2: Stipulations of C2 Level Security:


Ans: C2 security is a standard defined by the U.S. Department of Defense
for computer security. Its stipulations include:

● Discretionary Access Control (DAC): Ensuring authorized users have appropriate access.
● Auditing: Tracking all attempts to access the system.
● Object Reuse Protection: Preventing unauthorized access to deleted data.
● Identification and Authentication: Ensuring secure login mechanisms.

SQL

1: System Table Containing Information on Constraints ? Ans:


In most SQL systems, the system table storing constraints is:

○ For SQL Server: INFORMATION_SCHEMA.TABLE_CONSTRAINTS.


○ For Oracle: USER_CONSTRAINTS.

2: Difference Between TRUNCATE and DELETE:

Ans: TRUNCATE TABLE EMP:

● Removes all rows from the table without logging individual row deletions.
● Faster and does not allow rollback.

DELETE FROM EMP:

● Deletes rows matching a condition or all rows if no condition is specified.


● Allows rollback if within a transaction.
3. SQL QUERIES: write the SQL statements for the given queries.

Query 1: Find all employees with salary > 50000.


SELECT * FROM Employee WHERE Salary > 50000;

Query 2: Count the number of employees in each department.


SELECT DepartmentID, COUNT(*) AS EmployeeCount FROM Employee
GROUP BY DepartmentID;

Query 3: Display the highest salary in the company.


SELECT MAX(Salary) AS HighestSalary FROM Employee;

1. How many programmers have done the DCA course?

To count the number of programmers who have done the DCA course, we join the STUDIES table with the PROGRAMMER table on the common
field PNAME, and filter for the COURSE column with the value 'DCA':

SQL Query:

SELECT COUNT(DISTINCT S.PNAME) AS TotalDCAProgrammers

FROM STUDIES S

JOIN PROGRAMMER P ON S.PNAME = P.PNAME

WHERE S.COURSE = 'DCA';

2. How much revenue has been earned through the sale of packages developed in C?

To calculate the revenue earned, we filter the SOFTWARE table for the DEVIN field with the value 'C', and multiply the SCOST (software cost) by
the SOLD (number of units sold):

SQL Query:

SELECT SUM(SCOST * SOLD) AS TotalRevenue

FROM SOFTWARE

WHERE DEVIN = 'C';

Computer Networks

1. What is Frame Relay, and in which layer does it belong?


Frame Relay:

● Frame Relay is a packet-switched communication protocol designed for transmitting


data across wide area networks (WANs).
● It provides connection-oriented communication and operates at higher speeds compared
to older technologies like X.25.

Layer in OSI Model:

● Frame Relay primarily operates at the Data Link Layer (Layer 2) of the OSI model.

Key Features:

● Supports virtual circuits (PVCs and SVCs).


● Offers minimal error checking (unlike X.25) to ensure high performance.
● Suitable for bursty data traffic and cost-efficient for LAN-to-LAN connections.

Leetcode Questions

You might also like