Javatpoint Logo
Javatpoint Logo

C++ bitset set() Function

C++ bitset set() function is used to set all the bits to 1. If only a single parameter is passed, it sets the bit at that particular index to 1.

Syntax

Parameter

index: This parameter specifies the position at which the bit has to be set. The parameter is an optional one.

val: this parameter specifies a boolean value which has to bet set at the index. The parameter is an optional one.

Return value

It does not return any value.

Example 1

Output:

before applying set method : 1001
after applying reset method : 1111

Example 2

Output:

Before applying set() function: 1100
After applying set(1) function: 1110
Before applying set() function: 100100
After applying set(2, 0) and set(4, 1) function: 110000
Next TopicC++ bitset



Help Others, Please Share

facebook twitter pinterest