Found 7197 Articles for C++

Bitset all() function in C++ STL

sudhir sharma
Updated on 09-Aug-2019 12:21:03

177 Views

The bitset all() function an inbuilt function of the C++ STL( Standard Template Library). This function returns a Boolean value. The returned value is true if all the bits of the calling bitset are 1 else it will return false.The function does not accept any parameter and returns a Boolean value.SyntaxBool bitset_name .all()SampleBitset = 100101OutputfalseBecause all bits of the set need to be true in order to return a true value.Example#include using namespace std; void printer(bool val){    if(val){       cout

bitset::flip() in C++ STL

sudhir sharma
Updated on 09-Aug-2019 12:18:27

586 Views

The bitset flip() method is an inbuilt method of C++ STL( Standard Template Library). It flips the bits of the calling bitset. This method flips all 0’s to 1’s and all 1’s to 0’s, which means it reverse each and every bit of the calling bitset when no parameter is passed.If a parameter is passed the flip method will flip only the nth bit for the integer n passed. For example, if 5 is passed then the flip method will flip 5th bit of of the calling bitset.Syntaxbitset_name.flip(int pos)SampleInitial bitset: 011001After applying the bits flip function with no parameter: 100110After ... Read More

C++ Programming Internals?

sudhir sharma
Updated on 09-Aug-2019 07:28:43

564 Views

C++ Internals means how the working of C++ compiler compiling the .cpp code and giving us the output. C++ is a popular programming language mostly used for writing system software. It is an extension of the C programming language. C is a compiled language. The C++ compiler compiles C++ code to an object or executable file is generated. The executable or the binary files contains machine executable instructions and some metadata of the machine instructions.A typical way of compiling a C++ program is to run the compiler on C++ code. The compiler will generate machine instructions which are set of ... Read More

C++ mutable keyword?

sudhir sharma
Updated on 30-Jun-2025 11:23:16

5K+ Views

The mutable keyword in C++ is a storage class specifier. It enables non-static, non-const, and non-reference data members (i.e., mutable data member) of a class to be changed even when the object containing them is declared constant. Mutable data members are those members whose values can be changed in runtime even if the object is of constant type. It is just the opposite of a constant. What is Need of Mutable? Sometimes, it is necessary to modify one or more data members of a class/struct through the constant function, even if you do not want the function to update another ... Read More

C++ Program string class and its applications?

sudhir sharma
Updated on 08-Aug-2019 08:18:41

172 Views

String is a sequence of characters. In C++ programming language, The strings can be defined in two ways −C style strings: treats the string as a character array.String Class in C++The string class can be used in a C++ program from the library ‘string’. It stores the string as a character array in the memory but shows it as a string object to the user. In C++ there are many methods that support the C++ string class and help in the proper function of the object and increase the efficiency of the code.ExampleSome common string application are found where string ... Read More

C/C++ Programming to Count trailing zeroes in factorial of a number?

sudhir sharma
Updated on 08-Aug-2019 08:06:48

871 Views

Counting the number of trailing zeroes in a factorial number is done by counting the number of 2s and 5s in the factors of the number. Because 2*5 gives 10 which is a trailing 0 in the factorial of a number.ExampleFactorial of 7 = 5040, the number of trailing 0’s is 1.Based on our logic 7! = 2*3*4*5*6*7, it has 3 2s and 1 5s so the number of trailing 0’s is 1.#include using namespace std; int main() {    int n = 45;    int count = 0;    for (int i = 5; n / i >= 1; i *= 5)       count += n / i;    cout

C++ Programming for Smallest K digit number divisible by X?

sudhir sharma
Updated on 08-Aug-2019 07:55:02

131 Views

Smallest K digit number that divisible by X is found using the formula by checking divisible by X. The formula works in the following way −Compute minimum K digit number [min] for example: 10/100/1000 etc.Now find if min is divisible by X. if yes, then this is the answer.If not, then min+X - ([min+X]%k) is the answer.Example#include #include using namespace std; int main() {    int X = 83;    int K = 5;    cout

To count Vowels in a string using Pointer in C++ Program

sudhir sharma
Updated on 08-Aug-2019 07:36:50

2K+ Views

Finding the number of vowels in a string using pointers need you to understand string, vowels and how to use pointer with string.String is an array of characters. And vowels are characters from the set {a, e, i, o, u}. Pointer is a variable that stores the value of memory location on a variable.To find the number of vowels in a string. We will traverse the string and then compare each character with vowels and if it is equal then it increase a counter otherwise not.Condition of the below code is that it requires a string that has all lowercase ... Read More

To find sum of even factors of a number in C++ Program?

sudhir sharma
Updated on 30-Oct-2019 06:20:56

289 Views

This program is used to find all the even factors and calculate the sum of these even factors and display it as output.Example −Input : 30 Even dividers : 2+6+10+30 = 48 Output : 48For this, we will find all the factors. Find the even of them and find the sum, Else, we will use the formula to find the sum of factors using the prime factors, Sum of divisors = (1 + d11 + d12 ... d1a1) *(1 + d21 + d22 ... d2a2) *...........................* (1 + dk1 + dk2 ... dkak) Here di = prime factors ; ai ... Read More

5 Different methods to find the length of a string in C++?

sudhir sharma
Updated on 08-Aug-2019 07:07:55

2K+ Views

A sequence of characters or a linear array of character is known as String. Its declaration is same as define other arrays.Length of array is the number of characters in the String. There are many in-built method and other methods to find the length of string. Here, we are discussing 5 different methods to find the length of a string in C++.1) Using the strlen() method of C − This function returns an integer value of the C. For this you need to pass the string in the form of character array.PROGRAM TO ILLUSTRATE THE USE OF strlen() METHOD#include ... Read More

Advertisements