Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 941 of 2109
Process Synchronization in C/C++
Process synchronization is the technique to overcome the problem of concurrent access to shared data which can result in data inconsistency. A cooperating process is the one which can affect or be affected by other process which will lead to inconsistency in processes data therefore Process synchronization is required for consistency of data. Syntax /* General structure for process synchronization */ do { entry_section(); critical_section(); exit_section(); remainder_section(); } while(1); The Critical-Section Problem Every process has a reserved segment ...
Read MorePrinting source of a C program itself
In C programming, a self-printing program (also called a quine) is a program that prints its own source code as output. This can be achieved using the __FILE__ macro along with file I/O operations to read and display the current source file. Syntax FILE *fopen(__FILE__, "r"); The __FILE__ macro is a preprocessor macro that returns the name of the current source file as a string literal. This allows us to open and read our own source code at runtime. Example: Understanding __FILE__ Macro First, let's see how the __FILE__ macro works − ...
Read MoreC Program for Round Robin scheduling
Round Robin is a CPU scheduling algorithm designed for time-sharing systems. It operates like FCFS scheduling but with a crucial difference − each process gets a fixed time slice called a time quantum. When a process's time quantum expires, it is preempted and moved to the back of the ready queue, allowing other processes to execute. What is Round Robin Scheduling? Round Robin treats the ready queue as a circular queue where each process gets a small unit of time (10-100 milliseconds typically). The main advantages include fair CPU allocation and good response time for interactive systems. The ...
Read MorePriority Queue using Linked List in C
A priority queue is a special type of queue where elements are served based on their priority rather than the order of insertion. In C, we can implement a priority queue using a linked list where each node contains data, priority, and a pointer to the next node. In a priority queue, elements with higher priority (lower numerical value) are processed first. If two elements have the same priority, they follow FIFO order. Syntax typedef struct node { int data; int priority; struct node* ...
Read MoreC Program for FCFS Scheduling
We are given with the n number of processes i.e. P1, P2, P3, ..., Pn and their corresponding burst times. The task is to find the average waiting time and average turnaround time using FCFS CPU Scheduling algorithm. What is Waiting Time and Turnaround Time? Turnaround Time is the time interval between the submission of a process and its completion. Turnaround Time = completion of a process − submission of a process Waiting Time is the difference between turnaround time and burst time Waiting Time = turnaround time − burst time What is FCFS Scheduling? ...
Read MoreC Program for focal length of a lens
In optics, the focal length is a fundamental property of lenses that determines their converging or diverging power. Given the image distance and object distance from a lens, we can calculate the focal length using the lens equation. What is Focal Length? Focal length of an optical system is the distance between the center of lens or curved mirror and its focus. It represents the distance over which initially collimated rays are brought to a focus. ...
Read MoreCode valid in both C and C++ but produce different output
Here we will see programs that return different results when compiled with C or C++ compilers. These differences arise due to fundamental variations in how C and C++ handle certain language features. Character Literal Size Differences In C, character literals like 'a' are treated as int type, while in C++ they are treated as char type. This affects the result of the sizeof() operator − Example 1: C Code #include int main() { printf("Character: %c, Size: %d bytes", 'a', sizeof('a')); return 0; } ...
Read MoreWhat are the differences between bitwise and logical AND operators in C/C++
In C, the bitwise AND (&) and logical AND (&&) operators serve different purposes and work with different data types. Understanding their differences is crucial for correct C programming. Syntax // Bitwise AND result = operand1 & operand2; // Logical AND result = condition1 && condition2; Bitwise AND Operator (&) The bitwise AND (&) operator performs a bit-by-bit AND operation between two integers. It works on integer types and returns the same data type. Each corresponding bit is AND-ed according to these rules − 1 & 1 = 1 ...
Read MoreC Program Coin Change
In this problem, we are given a value n, and we want to make change of n rupees using a given set of coin denominations. We need to return the total number of ways to make the sum using these coins. Syntax int coinChange(int coins[], int numCoins, int amount); Example Input/Output Input: N = 6, coins = {1, 2, 4} Output: 6 Explanation: The total combinations that make the sum of 6 are: {1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 2}, {1, 1, 2, 2}, {1, 1, 4}, {2, 2, ...
Read MoreC / C++ Program for Dijkstra\'s shortest path algorithm
Dijkstra's algorithm is a greedy algorithm used to find the shortest path from a source vertex to all other vertices in a weighted graph. It works by maintaining a set of vertices whose shortest distance from the source has been determined and gradually expanding this set until all vertices are included. Syntax void dijkstra(int graph[V][V], int source); Algorithm Steps Step 1: Create a set to store vertices included in shortest path tree Step 2: Initialize all distances as INFINITE and source distance as 0 Step 3: Loop until all vertices are processed: ...
Read More