Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 5 of 81

System() Function in C/C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 38K+ Views

The system() function is a part of the C standard library that executes system commands. It is used to pass commands that can be executed in the command processor or terminal of the operating system, and returns the command's exit status after completion. Note: To use the system() function, include header file. Syntax int system(const char *command); Parameters command − A pointer to a null-terminated string containing the command to be executed. If NULL, checks if command processor is available. Return Value Returns the exit ...

Read More

Problem with scanf() when there is fgets()/gets()/scanf() after it in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 654 Views

In C programming, a common issue occurs when using scanf() followed by fgets(), gets(), or another scanf() for character input. The problem arises because scanf() leaves a newline character in the input buffer, which interferes with subsequent input functions. Syntax scanf("format_specifier", &variable); fgets(string, size, stdin); Problem 1: scanf() Followed by fgets() When scanf() reads an integer and is followed by fgets(), the newline character left by scanf() is immediately consumed by fgets() − #include int main() { int x; char str[100]; ...

Read More

Process Synchronization in C/C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 7K+ Views

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 More

Printing source of a C program itself

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 731 Views

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 More

C Program for Round Robin scheduling

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 10K+ Views

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 More

Priority Queue using Linked List in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 5K+ Views

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 More

C Program for FCFS Scheduling

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 56K+ Views

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 More

C Program for focal length of a lens

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 481 Views

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 More

C Program for Hexagonal Pattern

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 2K+ Views

We are given with an integer 'n' and the task is to generate the hexagonal pattern and display the final output. Syntax void pattern(int n); Example Let's see the hexagonal pattern for n=5 and n=4 − Input: n=5 Output: * * * * * * * * * * * * * * ...

Read More

C Program for Circumference of a Parallelogram

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 262 Views

We are given the sides of a parallelogram and the task is to calculate the circumference of the parallelogram with its given sides and display the result. What is a Parallelogram? A parallelogram is a type of quadrilateral which has − Opposite sides parallel and equal Opposite angles equal Diagonals bisect each other In the below figure, 'a' and 'b' are the sides of a parallelogram where parallel sides are shown. a a b b ...

Read More
Showing 41–50 of 809 articles
« Prev 1 3 4 5 6 7 81 Next »
Advertisements