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