Week 2
Week 2
RA2211003011350
Week 2
C Programming
- We can compare characters stored at two different memory locations using relational
operators like ==, <, or >.
Eg –
char a = 'A';
char b = 'B';
if (a == b) {
printf("Characters are equal\n");
} else {
printf("Characters are not equal\n");
}
Variable-size data objects: Their size can change during runtime. Example:
Dynamically allocated memory using malloc or calloc.
We should use fixed-size data object when the data size is known beforehand, providing
simpler code and lower overhead.
3. What is the purpose of the spawnl() function, and how is it used in a program?
- The spawnl() function is used to create a new process by replacing the current process
image with a new program image.
- In C, this code will not work because x is a const but not a compile-time constant. We need
a macro or #define.
C++ Programming
1. Output-
0
0
0
0
0
2. Output-
from base
from base
Technical Questions
Data Structures
Unix
DBMS
1. Primary Key:
o A unique identifier for a record in a table.
o Ensures each row has a unique value and cannot be NULL.
2. Secondary Key:
o A field or combination of fields used for data retrieval.
o It is not unique but helps index and access data efficiently.
Operating System
1. Binary Semaphore:
o A semaphore that takes only two values: 0 and 1.
o Used to manage access to a resource between processes or threads
(mutual exclusion).
2. Thrashing:
o A condition where excessive paging operations occur in a system due to
insufficient memory, leading to reduced performance.
SǪL
Computer Networks
1. Subnet:
o A smaller network within a larger network, created by dividing an IP
network using a subnet mask.
o It improves network management and security.
struct ListNode {
int data;
ListNode* next;
ListNode(int val) : data(val), next(nullptr) {}
};
int main() {
ListNode* head = nullptr;
addNode(head, 1);
addNode(head, 2);
addNode(head, 3);
addNode(head, 4);
addNode(head, 5);
cout << "Middle of the list: " << findMiddle(head) << endl;
head = nullptr;
addNode(head, 2);
addNode(head, 4);
addNode(head, 6);
addNode(head, 7);
addNode(head, 5);
addNode(head, 1);
cout << "Middle of the list: " << findMiddle(head) << endl;
return 0;
}
2-
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> arr1 = {2, 3, -8, 7, -1, 2, 3};
cout << "Maximum subarray sum: " << maxSubArraySum(arr1) << endl;
vector<int> arr2 = {-2, -4};
cout << "Maximum subarray sum: " << maxSubArraySum(arr2) << endl;
return 0;
}