main()
{
int a=4,b=2;
a=b<<a + b>>2;
printf("%d", a);
}

Answers were Sorted based on User's Feedback



main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }..

Answer / ram

Ans=32

Is This Answer Correct ?    270 Yes 22 No

main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }..

Answer / neha saxena

a=b<<a+b>>2
=2<<4+2>>2

According to precedence Table
1) + operated very 1st, (4+2=6)
2) then<< (left shift), (2<<6, 2 shifted left side 6 times
= 128)
3) and at last >> (right shift), (128>>2, 128 shifted right
side 2 times = 32)

Explanation in Answer No. 5, 6 & 7 are wrong

Is This Answer Correct ?    171 Yes 6 No

main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }..

Answer / satya

yes , the output will be 32....
<< and >> are bitwise operators... not relational ops..
reason:
<< means left shift operator..
>> means right shift operator..
for example.. if we give 2>>1
binary number for 2 is 0000 0010
the operator is right shift..so 0000 0001
for example.. if we give 2<<1
binary number for 2 is 0000 0010
the operator is left shift..so 0000 0100
go through this u will get the output...

Is This Answer Correct ?    78 Yes 10 No

main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }..

Answer / manish soni tagore collage jai

b<<a=2<<4=32;
and
b>>2=1>>2=0
so
32+0=32

Is This Answer Correct ?    47 Yes 5 No

main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }..

Answer / abhishek ranjan

32

Is This Answer Correct ?    37 Yes 3 No

main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }..

Answer / alamuru sreenivasa reddy

2<<4 that means 2 is left shifted by 4 times. then we will get 0010 0000=32 in decimal form. similarly 1>>2 means that is right shifted 2 times we will get 0000 0000=0.. so 0+32=32
i.e answer

Is This Answer Correct ?    24 Yes 10 No

main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }..

Answer / amalu

32

Is This Answer Correct ?    2 Yes 1 No

main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }..

Answer / vignya

size of integer is 8 bits
a=0000 0100, b=0000 0010;
b>>2 becomes 0000 0000 and b<<a becomes 0010 0000
on whole a= 0010 0000+ 0000 0000=0010 0000 =32

Is This Answer Correct ?    1 Yes 0 No

main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }..

Answer / sandeep kumar

Both shift operator has same precedence but associativity left to right so first calculate b>>2=0 then calculate b<<4=32 then add the both result

Is This Answer Correct ?    1 Yes 3 No

main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }..

Answer / aravind

It shows syntax error because relational operators are used only for checking conditions.

Is This Answer Correct ?    8 Yes 23 No

Post New Answer

More C Interview Questions

What is the heap in c?

0 Answers  


write a program to rearrange the array such way that all even elements should come first and next come odd

0 Answers  


/*what is the output for the code*/ void main() { int r; r=printf("naveen"); r=printf(); printf("%d",r); getch(); }

1 Answers   CDAC,


Explain what is the use of a semicolon (;) at the end of every program statement?

0 Answers  


What is the difference b/w Structure & Array?

6 Answers  






what is the output of below int n=10; (n++)++; printf("%d",n);

3 Answers  


what does ‘#include’ mean?

1 Answers   TCS,


What is build process in c?

0 Answers  


What is scanf () in c?

0 Answers  


ATM machine and railway reservation class/object diagram

0 Answers   Zycus Infotech,


Define macros.

0 Answers   Tech Mahindra,


Give a one-line C expression to test whether a number is a power of 2. [No loops allowed - it's a simple test.]

0 Answers  


Categories