C Bitwise Operations and Expressions
Test your knowledge of C programming bitwise operators, expression evaluation, and operator precedence with practical code output questions.
Questions
What is the output of the given program?
int main()
{
printf(%d,128>>4>>3>>2);
// Line 1
}
- 2
- 4
- 0
- 8
- Error at line 1
What is the output of the given program?
int main()
{
printf(%d,128<<4<<3<<2>>6);
// Line 1
}
- 65536
- 1024
- 0
- 512
- Error at line 1
What is the output of the given program?
int main()
{
int x = 24;
int y = 42;
printf("%d",(~x) | (~y) );
}
- - 25
- - 43
- - 9
- - 6
- Compiler error
What is the output of the given program?
int main()
{
int x = 24;
int y = 42;
int z = 37;
int a = 22;
printf(%d,x&y|z^a);
}
- 60
- 59
- 58
- 57
- 56
What is the output of the given code?
int main()
{
int x = 24; int y = 42;
int z = 37; int a = 22;
printf(%d,x|y|z|a );
}
- 64
- 59
- 62
- 63
- 77
What is the output of the given code?
int main()
{
printf("%d\\n",pow(128>>3>>2>>1,3));
}
- 16
- 8
- 0
- 4
- Compiler error
What is the output of the given code?
int main()
{
int x = 24; int y = 42;
int z = 37; int a = 22;
printf("%d",x&y^z|x~a );
}
- 63
- - 63
- 74
- - 74
- Compiler error
What is the output of the given code?
int main()
{
switch(printf("%d\\n",pow(128>>3>>2>>1,3))); case 56/4 :
printf("Hello"); case 32/4 : Printf("Bye"); case 0/9 :
Printf("Good"); case 0/1 : Printf("Bad");
}
- HelloByeGoodBad
- ByeGoodBad
- GoodBad
- Bad
- Compiler error
What is the output of the given code?
int main()
{
switch(printf("%d\\n",pow(128>>3>>2>>1,3)))
{
case 56/4 : printf("Hello"); case 32/4 :
printf("Bye"); case 0/9 :
printf("Good"); case 0/1 :
printf("Bad");
}
}
- 0 GoodBad
- 8ByeGoodBad
- 14HelloByeGoodBad
- 16
- Compiler error
What is the output of the given code?
int main()
{
int i=2;
int j=3;
int k=127;
printf("%h",++k>>++j<
- 32
- 20
- 16
- Blank Output Screen
- Compiler error
Find out the output of the given program, if any, or find out the error. Give the answer of the program in binary language.
int main()
{
int a=7,b=15,c;
c=a|b;
printf("the result comes out to be is :- %d",c);
}
- The result comes out to be: 0111.
- The result comes out to be: 1111.
- The result comes out to be is: 1000.
- The result comes out to be is: 0110.
- Compiler error
What is the output of the given code?
int main()
{
int i=2;
int j=3;
int k=127;
printf(%hx,++k>>++j<
- 32
- 20
- 16
- 4
- Compiler error
What is the output of the given code?
int main()
{
int i = 128<<2<<1<<0;
switch(i)
{
default : printf(Bye); case 128<<4<<3<<2>>6 :
printf(\\\\nHello); case 128<<4<<2<<2>>6 :
printf(\\\\nKeep Calm); case 128<<4<<4<<2>>3 :
printf(\\\\nGet Lost);
}
}
- ByeHello Keep CalmGet Lost
- Hello Keep CalmGet Lost
- Keep CalmGet Lost
- Get Lost
- Compiler error
What is the output of the given program?
int main()
{
int i = 128>>3>>2>>2; switch(i)
{
printf("Bye"); case 128<<4<<3<<2>>6 :
printf("\\nHello"); case 128<<4<<2<<2>>6 :
printf("\\nKeep Calm"); case 128>>3>>2>>9 :
printf("\\nGet Lost");
}
}
- ByeHelloKeep CalmGet Lost
- HelloKeep CalmGet Lost
- Keep CalmGet Lost
- Get Lost
- Blank screen
What is the output of the given code?
int main()
{
int i = 128<<4<<3<<2>>6;
switch(i) { default : printf(Bye); case 65536 :
printf(\\\\nHello); case 32 :
printf(\\\\nGood Bye); case 8/2 :
printf(\\\\nSee U Later);//Line 1
}
}
- Hello Good ByeSee U Later
- Bye
- Bye Hello Good Bye See U Later
- Good ByeSee U Later
- Error at line 1