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

ABCDCBA ABC CBA AB BA A A

4 Answers   TCS,


What is openmp in c?

0 Answers  


What's a "sequence point"?

3 Answers  


A stack can be implemented only using array?if not what is used?

3 Answers   InterGlobal,


What are directives in c?

0 Answers  






what does the following function print? func(int i) { if(i%2)return 0; eale return 1; } main() { int =3; i=func(i); i=func(i); printf("%d",i);}

9 Answers   TCS,


I need a sort of an approximate strcmp routine?

0 Answers  


What is an array in c?

0 Answers  


Why c is called a mid level programming language?

0 Answers  


what is function pointer?

2 Answers   Wipro,


what will the following program do? void main() { int i; char a[]="String"; char *p="New Sring"; char *Temp; Temp=a; a=malloc(strlen(p) + 1); strcpy(a,p); //Line no:9// p = malloc(strlen(Temp) + 1); strcpy(p,Temp); printf("(%s, %s)",a,p); free(p); free(a); } //Line no 15// a) Swap contents of p & a and print:(New string, string) b) Generate compilation error in line number 8 c) Generate compilation error in line number 5 d) Generate compilation error in line number 7 e) Generate compilation error in line number 1

1 Answers   IBM,


Is it possible to initialize a variable at the time it was declared?

0 Answers  


Categories