Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 putchar() function?

0 Answers  


WAP &#8211; represent a char in binary format

4 Answers   Motorola, Wipro,


What is the Difference between Macro and ordinary definition?

3 Answers   Bosch, Cognizant, College School Exams Tests, Motorola,


How can I set an array's size at run time?

9 Answers  


What is LINKED LIST? How can you access the last element in a linked list?

0 Answers   ADP,


Difference between fopen() and open()?

3 Answers   Aricent,


What is operator promotion?

0 Answers  


main() { float a=3.2e40; printf("%d",a); }

9 Answers   Satyam,


How do we print only part of a string in c?

0 Answers  


Why is it important to memset a variable, immediately after allocating memory to it ?

0 Answers  


write a program to swap two variables a=5 , b= 10 without using third variable

5 Answers  


what does " calloc" do?

7 Answers   Cadence, Logos,


Categories