Top | MCQs on Bitwise Algorithms and Bit Manipulations with Answers | Question 22

Last Updated :
Discuss
Comments

What will the below code do?

C++
void function(int& num, int pos) 
{
   num |= (1 << pos); 
}
C
void setBit(int* num, int pos) {
   *num |= (1 << pos); 
}
Java
void setBit(int[] num, int pos) {
   num[0] |= (1 << pos); 
}
Python
def set_bit(num, pos):
    return num | (1 << pos)
JavaScript
function setBit(num, pos) {
   return num | (1 << pos);
}

divide num by pos.

Multiply num by pos.

Add num with pos.

set the given position (pos) of a number (num).

Share your thoughts in the comments