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
Programming Articles
Page 37 of 2547
Producer-Consumer Problem in C
The producer-consumer problem is a classic synchronization challenge in concurrent programming where multiple threads share a common buffer. Producers generate data and place it into the buffer, while consumers remove and process data from the buffer. The main challenge is coordinating these operations to prevent race conditions and ensure data integrity. Syntax /* Basic structure for producer-consumer implementation */ pthread_t producer_thread, consumer_thread; pthread_mutex_t mutex; pthread_cond_t condition_variable; void* producer(void* arg); void* consumer(void* arg); Problem Statement The producer-consumer problem involves two types of processes − Producer − Generates data and puts it into ...
Read MoreC Program to Find Minimum Insertions to Form a Palindrome
A palindrome is a string that reads the same forwards and backwards. Given a string, we need to find the minimum number of character insertions required to make it a palindrome. We will explore three approaches − recursive, memoization, and dynamic programming. Syntax int minInsertions(char str[], int start, int end); Method 1: Recursive Approach The recursive approach compares characters from both ends. If they match, we move inward; otherwise, we try inserting at either end and take the minimum ? #include #include #include int findMin(int a, int b) ...
Read MoreDTH Sensor Programming
DHT11 and DHT22 sensors are digital sensors that can measure temperature and humidity. The DHT22 is more expensive but offers better accuracy and wider temperature ranges compared to DHT11. These sensors communicate with microcontrollers like ESP32 using a single−wire digital protocol. Syntax #include "DHT.h" #define DHT_PIN pin_number #define DHT_TYPE DHT11 // or DHT22 DHT sensor_object(DHT_PIN, DHT_TYPE); DHT11 Specifications Parameter DHT11 DHT22 Temperature Range 0°C to 50°C −40°C to 80°C Humidity Range 20% to 80% 0% to 100% Temperature Accuracy ±2°C ±0.5°C Humidity Accuracy ...
Read MoreHow Much Java is Better than C?
Java and C are two popular programming languages with different features, syntax, and applications. Java was first introduced by Sun Microsystems in 1995 and operates on the Java Virtual Machine (JVM). C is a procedural programming language developed by Dennis Ritchie at Bell Labs in 1972. Both Java and C have their pros and cons, but here we will explore how Java is better than C in various aspects. Memory Management One of the notable distinctions between Java and C is in memory management. C uses manual memory management, which requires the programmer to allocate and deallocate memory ...
Read MoreLocate unused structures and structure-members
Structures in C are user-defined data types that group related variables together. As codebases grow, some structures and their members may become unused, leading to cluttered code and wasted memory. This article explores methods to identify and remove unused structures and structure members in C programs. Syntax struct structure_name { data_type member1; data_type member2; // ... more members }; Why Remove Unused Structures and Members? Unused structures and members can impact performance and readability of your code. Here are some reasons why ...
Read MoreCorrupt stack problem in C, C++ program
The corrupt stack problem is a critical runtime issue in C programming that occurs when the program's stack memory becomes compromised. This can lead to unpredictable program behavior, crashes, and security vulnerabilities. Understanding stack corruption is essential for writing robust C programs. What is a Stack in C? In C, the stack is a region of memory used for automatic storage of local variables, function parameters, and return addresses. It operates on a Last-In-First-Out (LIFO) principle, where the most recently allocated memory is freed first when functions return. What is Corrupt Stack Problem? Stack corruption occurs ...
Read MoreC program to implement CHECKSUM
In computing, a checksum is a small-sized data value computed from a larger data set using an algorithm, with the intention that any changes made to the larger data set will result in a different checksum. Checksums are commonly used to verify the integrity of data during transmission or storage. Syntax unsigned int checksum(char *data); // Returns computed checksum value for given data Why Use CHECKSUM? There are several reasons why checksums are used − Error detection − Detect errors that occur during data transmission or storage Data integrity − Ensure data ...
Read Morefopen() for existing file in write mode in C
The fopen() function in C is used to open files for various operations. When opening an existing file in write mode, it's important to understand how different modes affect the file's content. Syntax FILE *fopen(const char *filename, const char *mode); fopen() for an Existing File in Write Mode When using fopen() with write mode on an existing file − 'w' mode: Creates a new file if it doesn't exist, or truncates (empties) an existing file before writing 'w+' mode: Same as 'w' but allows both reading and writing 'a' mode: Appends new ...
Read MoreC Program to Redeclaration of global variable
In C programming, variable redeclaration refers to declaring a variable more than once in the same scope. The behavior of redeclaration varies between global and local variables, and differs between C and C++. Understanding these differences is crucial for avoiding compilation errors. Syntax // Global variable redeclaration int var; int var; // Allowed in C without initialization // Local variable redeclaration int main() { int var; int var; // Not allowed in C } Global Variable Redeclaration Without Initialization C allows ...
Read MoreC program to demonstrate usage of variable-length arrays
Variable-length arrays (VLAs) in C allow you to create arrays whose size is determined at runtime rather than compile time. This feature was introduced in C99 and provides dynamic array allocation on the stack. In this example, we'll demonstrate a library system that uses VLAs to manage books on shelves with three operations: adding books, querying book pages, and counting books per shelf. Syntax data_type array_name[variable_size]; // Where variable_size is determined at runtime Library Management System The system supports three commands − Command 1: Insert a book with y pages at shelf ...
Read More