C Bitwise Operators - Aptitude Questions and Answers

C programming Bitwise Operators Aptitude Questions and Answers: In this section you will find C Aptitude Questions and Answers on Bitwise Operators like Bitwise OR (|), Bitwise AND (&), Bitwise NOT (!).

1) Which is not a bitwise operator?

  1. &
  2. |
  3. <<
  4. &&

2) Predict the output of following program.

#include <stdio.h>

int main()
{
	int a=10;
	int b=2;
	int c;
	
	c=(a & b);
	printf("c= %d",c);
	
	return 0;
}
  1. c= 12
  2. c= 10
  3. c= 2
  4. c= 0

3) Predict the output of following program.

#include <stdio.h>

#define MOBILE  0x01
#define LAPPY   0x02

int main()
{
	unsigned char  item=0x00;

	item |=MOBILE;
	item |=LAPPY;

	printf("I have purchased ...:");
	if(item & MOBILE){
		printf("Mobile, ");
	}
	if(item & LAPPY){
		printf("Lappy");
	}

	return 1;
}
  1. I have purchased ...:
  2. I have purchased ...:Mobile, Lappy
  3. I have purchased ...:Mobile,
  4. I have purchased ...:Lappy

4) Predict the output of following program.

#include <stdio.h>

int main()
{
	char var=0x04;

	var = var | 0x04;
	printf("%d,",var);
	var |= 0x01;
	printf("%d",var);
	
	return 0;
}
  1. 8,9
  2. 4,5
  3. 8,8
  4. 4,4

5) Predict the output of following program.

#include <stdio.h>

int main()
{
	char flag=0x0f;

	flag &= ~0x02;
	printf("%d",flag);

	return 0;
}
  1. 13
  2. d
  3. 22
  4. 10

6) Consider the given statement:

int x = 10 ^ 2

What will be the value of x?

  1. 5
  2. 6
  3. 7
  4. 8


7) Predict the output of following program.

#include <stdio.h>

int main()
{
    int x=10;
    
    x &= ~2;
    printf("x= %d",x);
    
    return 0;
}
  1. x= 10
  2. x= 8
  3. x= 12
  4. x= 0

8) Which Bitwise Operator can be used to check whether a number is EVEN or ODD quickly?

  1. Bitwise AND (&)
  2. Bitwise OR (|)
  3. Bitwise XOR (^)
  4. Bitwise NOT (~)

9) Which statement is suitable to check 3rd (count from 0) bit is high (set) or not?

  1. (num & (1<<3))
  2. (num & 0x08)
  3. (num & 0x03)
  4. Both (1) and (2)

10) Left shift (<<) and Right shift (>>) operators are equivalent to _____________ by 2.

Choose the correct words...

  1. Multiplication and Division
  2. Division and Multiplication
  3. Multiplication and Remainder
  4. Remainder and Multiplication





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.