Skip to content
Related Articles

Related Articles

bitset reset() function in C++ STL
  • Last Updated : 18 Jun, 2018

bitset::reset() is a built-in function in C++ STL which resets the bits at the given index in the parameter. If no parameter is passed then all the bits are reset to zero.

Syntax:

reset(int index) 

Parameter: The function accepts a parameter index which signifies the position at which the bit has to be reset to zero. If no parameter is passed, all the bits in the bitset are reset to zero.

Return Value: The function does not return anything.

Below programs illustrates the bitset::reset() function.



Program 1:




// CPP program to illustrate the
// bitset::reset() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // Initialization of bitset
    bitset<4> b1(string("1100"));
    bitset<6> b2(string("111111"));
  
    // Function that resets all bits
    cout << "Before applying reset() function: "
         << b1 << endl;
  
    b1.reset();
    cout << "After applying reset() function: "
         << b1 << endl;
  
    // Function that resets all bits
    cout << "Before applying reset() function: "
         << b2 << endl;
  
    b2.reset();
    cout << "After applying reset() function: "
         << b2 << endl;
  
    return 0;
}
Output:
Before applying reset() function: 1100
After applying reset() function: 0000
Before applying reset() function: 111111
After applying reset() function: 000000

Program 2:




// CPP program to illustrate the
// bitset::reset() function
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
    // Initialization of bitset
    bitset<4> b1(string("1101"));
    bitset<6> b2(string("111111"));
  
    // Function that resets all bits
    cout << "Before applying reset() function: "
         << b1 << endl;
    b1.reset(2);
    cout << "After applying reset(2) function: "
         << b1 << endl;
  
    // Function that resets all bits
    cout << "Before applying reset() function: "
         << b2 << endl;
  
    b2.reset(3);
    b2.reset(5);
    cout << "After applying reset(3) and reset(5) function: "
         << b2 << endl;
  
    return 0;
}
Output:
Before applying reset() function: 1101
After applying reset(2) function: 1001
Before applying reset() function: 111111
After applying reset(3) and reset(5) function: 010111
Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
My Personal Notes arrow_drop_up
Recommended Articles
Page :