C++ Articles

Page 6 of 597

What are the differences between bitwise and logical AND operators in C/C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 8K+ Views

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 More

C / C++ Program for Dijkstra\'s shortest path algorithm

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 27K+ Views

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

What is OpenMP?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 8K+ Views

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 More

C/C++ Function Call Puzzle?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 298 Views

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 More

C/C++ Tricky Programs

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 6K+ Views

Here are 10 tricky C programming challenges that will test your understanding of language fundamentals and creative problem-solving techniques. 1. Program to Print Double Quotes in C Printing double quotes in C requires escape sequences since quotes are used to delimit string literals. We use the backslash escape sequence " to print quotes − #include int main() { printf(""Tutorials Point ""); return 0; } "Tutorials Point " 2. Print Numbers 1 to 10 Without Loops or Goto When loops and ...

Read More

C/C++ Program for Greedy Algorithm to find Minimum number of Coins

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 6K+ Views

A greedy algorithm is an algorithmic approach used to find an optimal solution for the given problem. Greedy algorithm works by finding locally optimal solutions (optimal solution for a part of the problem) of each part so that the global optimal solution can be found. In this problem, we will use a greedy algorithm to find the minimum number of coins/notes that could makeup to the given sum. For this we will take under consideration all the valid coins or notes i.e. denominations of { 1, 2, 5, 10, 20, 50, 100, 200, 500, 2000 }. We need to ...

Read More

Difference between C and C++

Akansha Kumari
Akansha Kumari
Updated on 15-Mar-2026 9K+ Views

Both C and C++ are middle-level programming languages that are used for developing system software as well as application software. C is a procedural programming language which have low-level memory access and minimal runtime; therefore, it is used for writing operating systems, embedded systems, and system-level programs. whereas C++ is just an extension of the C language, which is both a procedural programming language and object-oriented. Therefore, having extra features that make it suitable for game development, GUI applications, and high-performance software. C Programming Language C is a general-purpose, procedural programming language, which was developed by Dennis ...

Read More

Alternate vowel and consonant string in C/C++?

Nishu Kumari
Nishu Kumari
Updated on 15-Mar-2026 558 Views

We are given a string with both vowels and consonants. Our task is to rearrange it so that vowels and consonants appear alternately, while keeping their original order within their groups. This rearrangement is only possible if the number of vowels and consonants is equal, or their difference is exactly one. If multiple valid arrangements are possible, we return the one that is lexicographically smaller. Syntax char* alternateVowelConsonant(char* str); bool isVowel(char ch); Example Scenarios Scenario 1 Input: "objective" Output: "obejctive" Explanation: Vowels = [o, e, i, e], Consonants = [b, j, ...

Read More

C/C++ Program for Finding the Number Occurring Odd Number of Times?

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 535 Views

In C programming, finding the number that occurs an odd number of times in an array is a common problem. Given an array where all elements appear an even number of times except one, we need to identify that unique element. Consider the array [1, 2, 1, 3, 3, 2, 2]. Here, the number 2 appears 3 times (odd), while others appear even times. Example Scenarios Input: arr[] = {5, 7, 8, 8, 5, 8, 8, 7, 7} Output: 7 The number 7 appears 3 times (odd frequency). Input: arr[] = {2, 3, 2, 1, ...

Read More

C/C++ Program to Find the sum of Series with the n-th term as n^2 – (n-1)^2

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 385 Views

This program finds the sum of a mathematical series where the n-th term is defined as Tn = n2 - (n-1)2. We need to calculate the sum Sn = T1 + T2 + T3 + ... + Tn modulo (109 + 7). Syntax result = ((n % mod) * (n % mod)) % mod; Mathematical Derivation First, let's simplify the term Tn − Tn = n2 - (n-1)2 Tn = n2 - (n2 - 2n + 1) Tn = n2 - n2 + 2n - 1 Tn = 2n - 1 ...

Read More
Showing 51–60 of 5,962 articles
« Prev 1 4 5 6 7 8 597 Next »
Advertisements