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
C Articles
Page 48 of 96
What 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 MoreC/C++ Function Call Puzzle?
This C/C++ function call puzzle explores the different behavior of function calling between C and C++ programming languages. The key difference lies in how each language handles function parameters and argument passing. When a function is declared without parameters, C and C++ treat it differently. Let's examine this behavior with a practical example. Syntax return_type function_name(); // Function declaration without parameters Example The following code demonstrates the different behavior when calling a function with arguments that was declared without parameters − #include void method() { ...
Read MoreC program to check if a given string is Keyword or not?
In C programming, a keyword is a predefined or reserved word that has a fixed meaning and is used to perform specific operations. The C language has 32 keywords that cannot be used as variable names or identifiers. Syntax int strcmp(const char *str1, const char *str2); We can check if a string is a keyword by comparing it with all C keywords using the strcmp() function. C Keywords The following table lists all 32 keywords in the C programming language − ...
Read MoreSum of the series 1.2.3 + 2.3.+ ... + n(n+1)(n+2) in C
Find the sum up to n terms of the series: 1.2.3 + 2.3.4 + ... + n(n+1)(n+2). In this series, 1.2.3 represents the first term and 2.3.4 represents the second term. Let's see an example to understand the concept better − Input: n = 5 Output: 420 Explanation 1.2.3 + 2.3.4 + 3.4.5 + 4.5.6 + 5.6.7 = 6 + 24 + 60 + 120 + 210 = 420 The nth term = n(n+1)(n+2); where n = 1, 2, 3, ... Expanding: n(n+1)(n+2) = n(n² + 3n + 2) = n³ + ...
Read MoreBetrothed numbers in C?
Betrothed numbers are pairs of numbers where the sum of proper divisors of each number equals the other number plus one. In mathematical terms, for numbers (a, b) to be betrothed: s(a) = b + 1 and s(b) = a + 1, where s(n) represents the sum of proper divisors of n (divisors excluding the number itself). The first few pairs of betrothed numbers are: (48, 75), (140, 195), (1050, 1925), (1575, 1648), (2024, 2295), (5775, 6128). All known pairs have opposite parity − one number is even and the other is odd. Syntax int sumOfProperDivisors(int ...
Read MoreArray elements that appear more than once in C?
An array is a container of elements of the same data type. Elements can appear in any order and frequency within an array. In this article, we will learn how to find elements that appear more than once in an array. Syntax for (i = 0; i < n; i++) { count = 0; for (j = 0; j < n; j++) { if (arr[i] == arr[j]) { count++; ...
Read MoreArray sum after dividing numbers from previous in C?
In C programming, we can calculate the sum of an array where each element (except the first) is divided by its preceding element. This problem involves integer division, where we only consider the quotient part of the division. Syntax sum = arr[0]; for(i = 1; i < n; i++) { sum += arr[i] / arr[i-1]; } Algorithm The algorithm traverses each element of the array and divides it by the element preceding it. Then, it adds the quotient value to the sum variable − Input : Array - ...
Read More_Generic keyword in C ? 1: 20
The _Generic keyword in C is used to define type-generic macros that can work with different data types. This keyword was introduced in the C11 standard to enable compile-time type selection, allowing a single macro to behave differently based on the type of its argument. Syntax #define macro_name(x) _Generic((x), \ type1: expression1, \ type2: expression2, \ default: default_expression \ )(x) The _Generic expression evaluates to one of the specified expressions based on the type of the controlling expression (x). Parameters ...
Read MoreA Product Array Puzzle in C?
A Product Array Puzzle is a common programming problem where we need to construct an array such that each element contains the product of all elements in the original array except the element at that position. The constraint is that we cannot use the division operator. Syntax void productArray(int arr[], int n, int result[]); // arr[] - input array // n - size of array // result[] - output array containing products Approach: Using Left and Right Product Arrays The solution uses two auxiliary arrays to store products of elements to the ...
Read More