Question 11
What condition should be applied in the below code snippet to check whether a number is even or odd using Bitwise Operator?
// C++ program to check for even or odd
// using Bitwise operator
#include <iostream>
using namespace std;
// Returns true if n is even, else odd
bool isEven(int n)
{
if (______)
return 0;
return 1;
}
// Driver code
int main()
{
int n = 10;
isEven(n) ? cout << "Even" : cout << "Odd";
return 0;
}
Question 12
What will be the output of the following code for N=128?
int function(unsigned n)
{
if (!isPowerOfTwo(n))
return -1;
unsigned i = 1, pos = 1;
while (!(i & n)) {
i = i << 1;
++pos;
}
return pos;
}
Question 13
What will the below code do?
void bin(unsigned n)
{
if (n > 1)
bin(n / 2);
cout << n % 2;
}
Question 17
What will the do the below code snippet?
const int x = 32;
char *function(char *a)
{
for (int i=0; a[i]!='\0'; i++)
a[i] = a[i] & ~x;
return a;
}
Question 18
What are we doing in the below code snippet?
unsigned int function(int n)
{
unsigned int count = 0;
while (n) {
n &= (n - 1);
count++;
}
return count;
}
Question 19
What will do the below code?
bool fun(int x, int y)
{
return ((x ^ y) < 0);
}
There are 30 questions to complete.