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
Articles by Arnab Chakraborty
Page 13 of 377
MCQ on Memory allocation and compilation process in C
Here we will see some MCQ questions on Memory Allocation and Compilation Processes in C programming language. Question 1: Union Memory Allocation What will be the output of the following code − #include #include int main() { union my_union { int i; float f; char c; }; union my_union* u; u = (union ...
Read MoreImplicit Threading and Language-based threads
Implicit threading is a programming approach where the creation and management of threads is handled by compilers and run-time libraries rather than application developers. This approach simplifies multithreaded programming by abstracting away low-level thread management details. Syntax #pragma omp parallel { // Parallel code block } OpenMP for Implicit Threading OpenMP is a widely-used implicit threading library for C, C++, and FORTRAN. It provides compiler directives and an API for parallel programming in shared-memory environments. OpenMP identifies parallel regions as blocks of code that can execute in parallel − ...
Read MoreWindows thread API in the C program
Threads are created in the Windows API using the CreateThread() function. Just as in Pthreads, a set of attributes like security information, the size of the stack, and a flag for the thread is passed to this function. In the below program, we use the default values for these attributes. Once the summation thread is created, the parent must wait for it to complete before outputting the value of Sum, as the value is set by the summation thread. Using the WaitForSingleObject() function, we perform the equivalent of pthread_join() in the Windows API, which causes the creating thread to ...
Read MoreGrand Central Dispatch (GCD)
Grand Central Dispatch (GCD) is a technology for Apple's Mac OS X and iOS operating systems that provides a combination of extensions to the C language, an API, and a runtime library. It allows application developers to identify sections of code to run in parallel, managing most of the threading details automatically like OpenMP. Syntax // Block syntax ^{ /* code block */ } // Dispatch queue creation dispatch_queue_t dispatch_get_global_queue(long identifier, unsigned long flags); // Async execution void dispatch_async(dispatch_queue_t queue, dispatch_block_t block); Blocks in GCD GCD introduces extensions to the C and ...
Read MoreWhat is OpenMP?
OpenMP (Open Multi-Processing) is a set of compiler directives and an API for programs written in C, C++, or FORTRAN that provides support for parallel programming in shared-memory environments. OpenMP identifies parallel regions as blocks of code that may run concurrently across multiple threads. Syntax #pragma omp parallel { // Code block to execute in parallel } How OpenMP Works Application developers insert compiler directives into their code at parallel regions, and these directives instruct the OpenMP run-time library to execute the region in parallel. When OpenMP encounters the #pragma ...
Read MoreWindows Anonymous Pipe
Windows anonymous pipes are unidirectional communication channels that enable data transfer between parent and child processes. They behave similarly to UNIX pipes but use Windows-specific APIs. Reading and writing operations are performed using standard ReadFile() and WriteFile() functions. Syntax BOOL CreatePipe( PHANDLE hReadPipe, // Read handle PHANDLE hWritePipe, // Write handle LPSECURITY_ATTRIBUTES sa, // Security attributes DWORD nSize ...
Read MoreBinary Search using pthread in C Program?
Binary search is one of the most efficient searching algorithms for sorted arrays. It works by repeatedly dividing the search space in half. In this article, we'll explore how to implement binary search using multiple threads (pthread) in C to potentially improve performance by parallelizing the search across different segments of the array. Syntax #include int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg); int pthread_join(pthread_t thread, void **retval); Example: Multithreaded Binary ...
Read MoreBinary representation of next greater number with same number of 1's and 0's in C Program?
In C programming, finding the binary representation of the next greater number with the same number of 1's and 0's is a classic problem that can be solved using a next-permutation approach. Given a binary string, we need to find the smallest binary number that is greater than the given number and contains exactly the same count of 0's and 1's. Syntax char* nextBinary(char* bin); Algorithm The algorithm works in two main steps − Find the rightmost '01' pattern and swap it to '10' Rearrange all bits after the swap position to ...
Read MoreBFS using vectors & queue as per the algorithm of CLRS in C Program?
In graph theory, BFS (Breadth-First Search) is a fundamental traversal algorithm described in CLRS (Introduction to Algorithms). It explores vertices level by level using a queue data structure and maintains vertex states using colors. Syntax void BFS(int graph[][MAX_VERTICES], int vertices, int source); Algorithm The CLRS BFS algorithm uses the following pseudocode − BFS(G, s) - begin for each vertex u in G.V - {s}, do u.color := white u.d := infinity ...
Read MoreBetrothed numbers in C Program?
Betrothed numbers are a special pair of numbers where the sum of proper divisors of one number equals one more than the other number. These mathematical curiosities demonstrate interesting relationships between divisibility and number theory. Syntax int sumOfProperDivisors(int n); void findBetrothedPairs(int limit); Understanding Betrothed Numbers For example, the pair (48, 75) are betrothed numbers − Proper divisors of 48: {1, 2, 3, 4, 6, 8, 12, 16, 24}, sum = 76 Proper divisors of 75: {1, 3, 5, 15, 25}, sum = 49 Since 76 = 75 + 1 and 49 = ...
Read More