bitset operator[] in C++ STL Last Updated : 12 Nov, 2020 Comments Improve Suggest changes Like Article Like Report bitset::operator[] is a built-in function in C++ STL which is used to assign value to any index of a bitset. Syntax: bitset_operator[index] = value Parameter: The parameter index specifies the position at which the value is to be assigned. Return Value: The function returns the value to the bit at the index. Below programs illustrate the bitset::operator[] function. Program 1: C++ // C++ program to illustrate the // bitset::operator[] #include <bits/stdc++.h> using namespace std; int main() { // Initialization of bitset // by zeros of size 6 bitset<6> b; // initialises second index as 1 b[2] = 1; // initialises fifth index as 1 b[5] = 1; // prints the bitset cout << "The bitset after assigning values is: " << b; return 0; } Output: The bitset after assigning values is: 100100 Program 2: C++ // C++ program to illustrate the // bitset::operator[] // assign value from a index #include <bits/stdc++.h> using namespace std; int main() { // Initialization of bitset // by zeros of size 6 bitset<6> b; // initialises second index as 1 b[2] = 1; // initialises fifth index as the same as b[2] b[3] = b[2]; b[0] = b[5]; // prints the bitset cout << "The bitset after assigning values is: " << b; return 0; } Output: The bitset after assigning values is: 001100 Program 3: C++ // C++ program to illustrate the // bitset::operator[] // prints the value of bit at index #include <bits/stdc++.h> using namespace std; int main() { // Initialization of bitset // by zeros of size 6 bitset<6> b; // initialises second index as 1 b[2] = 1; // initialises fifth index as the same as b[2] b[3] = b[2]; b[0] = b[5]; cout << "The bit value at index 3 is " << b[3]; return 0; } Output: The bit value at index 3 is 1 Comment More infoAdvertise with us Next Article bitset operator[] in C++ STL G gopaldave Follow Improve Article Tags : Misc C++ STL CPP-Functions CPP-bitset +1 More Practice Tags : CPPMiscSTL Similar Reads Bitwise Operators in C++ In C+, Bitwise Operators are the operators that are used to perform bit-level operations on the integers. While performing these operations, integers are considered as sequences of binary digits. These operators are useful for low-level programming, system programming, and optimizing performance.C++ 6 min read Bitwise Operators in C In C, bitwise operators are used to perform operations directly on the binary representations of numbers. These operators work by manipulating individual bits (0s and 1s) in a number.The following 6 operators are bitwise operators (also known as bit operators as they work at the bit-level). They are 6 min read bitset none() in C++ STL bitset::none() is a built-in STL in C++ which returns True if none of its bits are set. It returns False if a minimum of one bit is set. Syntax: bool none() Parameter: The function accepts no parameter. Return Value: The function returns a boolean. The boolean value is True if none of its bits are s 2 min read bitset size() in C++ STL bitset::size() is a built-in STL in C++ which returns the total number of bits. Syntax: bitset_name.size() Parameter: The function accepts no parameter. Return Value: The function returns an integral value which signifies the number of bits. It eventually returns the size that has been given while i 2 min read array::operator[ ] in C++ STL Array classes are generally more efficient, light-weight, and reliable than C-style arrays. The introduction of array class from C++11 has offered a better alternative for C-style arrays. array::operator[] This operator is used to reference the element present at position given inside the operator. 2 min read Like