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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is sprintf unsafe?

613


please send me the code for multiplying sparse matrix using c

1717


What is use of pointer?

583


What is p in text message?

533


how to introdu5ce my self in serco

1519






What is d scanf?

581


What is the g value paradox?

640


What is New modifiers?

660


which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above

1409


What is openmp in c?

605


Differentiate between ordinary variable and pointer in c.

612


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

1491


What are the differences between Structures and Arrays?

601


Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays

1884


Why isnt any of this standardized in c?

629