bitset reset() function in C++ STL

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


Output:

Before applying reset() function: 1100
After applying reset() function: 0000
Before applying reset() function: 111111
After applying reset() function: 000000

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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;
}

chevron_right


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


My Personal Notes arrow_drop_up

The function of education is to teach one to think intensively and to think critically

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.