Programming Articles

Page 1380 of 2547

is_fundamental Template in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 277 Views

In this article we will be discussing the working, syntax and examples of std::is_fundamental template in C++ STL.is_ fundamental is a template which comes under the header file. This template is used to check whether the given type T is a fundamental data type or not.What is Fundamental type?Fundamental types are the built-in types which are already declared in the compiler itself. Like int, float, char, double, etc. These are also known as built-in data types.All the data types which are user-defined like: class, enum, struct, references or pointers, are not part of the fundamental type.Syntaxtemplate is_fundamental;ParametersThe template ...

Read More

Bulb Switcher III in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 498 Views

Suppose we have a room with n bulbs, these are numbered from 1 to n, arranged in a row from left to right. Initially, all the bulbs are turned off. At moment k (for k in range 0 to n - 1), we turn on the light[k] bulb. A bulb changes color to blue only if it is on and all the previous bulbs (to the left) are turned on too. We have to find the number of moments in which all turned on bulbs is blue. So this is an example −The output will be 3 as the moments ...

Read More

multiset size() in C++ STL with Examples

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 199 Views

In this tutorial, we will be discussing a program to understand multiset size() in C++ STL.The function size() returns the number of elements present into a given container.Example#include using namespace std; int main(){    multiset s;    s.insert(10);    s.insert(13);    cout

Read More

Score After Flipping Matrix in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 242 Views

Suppose we have a two dimensional matrix A where each value is 0 or 1. Here a move consists of choosing any row or column, and toggling each value in that row or column: changing all 0s to 1s, and all 1s to 0s. Now after making any number of moves, every row of this matrix is interpreted as a binary number, and the score of the matrix is the sum of these numbers. So our task is to find the highest possible score. If the input is like −001110101100The output will be 39 as after toggling, the matrix will ...

Read More

Position of rightmost set bit in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 490 Views

In this problem, we are given a number N. Our task is to print the index of the rightmost set bit of the number.Let’s take an example to understand the problem, Input − 4Output − 3Explanation − binary of 4 is 100, the index of the rightmost set bit is 3.To solve this problem, a simple solution would be shifting the number till a set bit is encountered but this could take a lot of computation if the number is large.A more efficient solution will be using boolean algebra. For this we will first calculate 2’s complement of the number, ...

Read More

How to quickly swap two arrays of the same size in C++?

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 301 Views

In this tutorial, we will be discussing a program to understand how to quickly swap two arrays of same size in C++.For this we will be using a quick method called std::swap() for swapping the elements of the two given arrays.Example#include #include using namespace std;    int main (){    int a[] = {1, 2, 3, 4};    int b[] = {5, 6, 7, 8};    int n = sizeof(a)/sizeof(a[0]);    swap(a, b);    cout

Read More

is_pod template in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 221 Views

In this article we will be discussing the working, syntax and examples of std::is_pod template in C++ STL.is_ pod is a template which comes under header file. This template is used to check whether the given type T is a POD(plain-old-data) type or not.What is POD(Plain old data)?Plain old data(POD) types are those types which are also in old C language. POD types also include scalar types. POD class type is that class type which is both, trivial (which can be initialised statically) and standard layout (which is a simple data structure like struct and union).Syntaxtemplate is_pod;ParametersThe template ...

Read More

Prime Palindrome in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have to find the smallest prime palindrome that is greater than or equal to N. So if the N is 13, then the smallest palindrome will be 101.To solve this, we will follow these steps −If N is in range 8 to 11, then return 11for i in range 1 to 99999s := i as a stringr := sreverse rnum := concatenate s and substring of r from index 1, then convert to numberif num >= N and num is prime, then return numreturn 0Let us see the following implementation to get better understanding −Example#include using namespace ...

Read More

Position of rightmost different bit in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 445 Views

In this problem, we are given two numbers N and M. Our task is to find the index of the rightmost different bit in the binary representation of the number.Let’s take an example to understand the problem, Input − N = 12 , M = 9Output − 2Explanation − (12)2 = 1100 and (10)2 = 1010.The second bit from right is a different bit.To solve this problem, we will have to find all the different bits of the numbers. To find all different bits we will find xor of M and N. Then we will find the rightmost bit of M^N.This seems ...

Read More

is_pointer Template in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 505 Views

In this article we will be discussing the working, syntax and examples of std::is_pointer template in C++ STL.is_ pointer is a template which comes under the header file. This template is used to check whether the given type T is a pointer type or not.What is a Pointer?Pointers are non-static types which hold an address of another type or in other words which points to some memory location in the memory pool. With help of an asterisk (*) we define a pointer and when we want to refer the specific memory which the pointer is holding then also we ...

Read More
Showing 13791–13800 of 25,466 articles
Advertisements