Question 21
What will the output of the following code for N = 5 and K =2?
bool function(int n, int k)
{
bool bit = n & (1 << k);
return bit;
}
Question 22
What will the below code do?
void function(int& num, int pos)
{
num |= (1 << pos);
}
Question 23
What is the output of the below code?
#include <bits/stdc++.h>
using namespace std;
int main()
{
if (~0 == 1)
cout << "Yes";
else
cout << "No";
}
Question 24
Predict the output:
#include <iostream>
using namespace std;
int main()
{
int x = -5;
x = x >> 1;
cout << x << endl;
return 0;
}
Question 25
If we have to add two numbers without having any carry, which bitwise operator should be used?
Question 26
Bitwise & can be used in conjunction with ~ operator to turn off 1 or more bits in a number.
Question 29
Which is the format specifier used to prefix 0x and print a number in hexadecimal notation.?
Question 30
What is the output of the below code for input num = 15?
unsigned int fun(unsigned int n)
{
unsigned int count = 0;
while (n) {
count += n & 1;
n >>= 1;
}
return count;
}
There are 30 questions to complete.