what is the output of below code
int x=8,y;
x>>=2;
y=x;
what is y value.

NOTE:EXPLANATION IS COMPALSARY with binary bits

Answers were Sorted based on User's Feedback



what is the output of below code int x=8,y; x>>=2; y=x; what is y value. NOTE:EXPLANATI..

Answer / rajiv

2

Is This Answer Correct ?    6 Yes 0 No

what is the output of below code int x=8,y; x>>=2; y=x; what is y value. NOTE:EXPLANATI..

Answer / kittu

x=8 means x is equivalent to 00001000 in bit wise environment.

x>>=2 is equivalent to x=(x>>2)
x>>2 makes a bitwise shift to x 2 times.that is now the bit
code is 00000010. that is 2.
and this is assigned to x.So when y is assigned by x viz
y=x; y value gets changed to 2.
Hence 2 is printed.

EXPLANATION:-When >> (right shift operator) is applied to a
byte
the bits in the byte get shifted to right by the number
specified on right side..

Ex:- 6>>1 implies

binary code of 6 is : 00000110
when shifted right : 00000011 which is 3 that is 6 divided
by 2.
Note that when shift operator is used the bits shift but not
rotate...That is once shift operator is applied the bits get
lost...

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More C Interview Questions

What is the full form of getch?

0 Answers  


Explain the properties of union.

0 Answers  


write a program to sort the elements in a given array in c language

10 Answers   TCS,


I heard that you have to include stdio.h before calling printf. Why?

0 Answers  


Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon

0 Answers   HCL,


different between overloading and overriding

3 Answers  


how does the C compiler interpret the following two statements p=p+x; q=q+y; a. p=p+x; q=q+y b. p=p+xq=q+y c. p=p+xq; q=q+y d. p=p+x/q=q+y

2 Answers   TCS, Tech Synergy,


What is the purpose of scanf() and printf() functions?

0 Answers  


what will be the output of this program main() { int i=1; while (i<=10); { i++; } }

11 Answers  


write a c program to find the roots of a quadratic equation ax2 + bx + c = 0

11 Answers   CSC, St Marys, TATA,


what is data structure.in linear and non linear data structures which one is better?Explain

3 Answers   Wipro,


Does c have circular shift operators?

0 Answers  


Categories