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
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 |
ABCDCBA ABC CBA AB BA A A
What is openmp in c?
What's a "sequence point"?
A stack can be implemented only using array?if not what is used?
What are directives in c?
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);}
I need a sort of an approximate strcmp routine?
What is an array in c?
Why c is called a mid level programming language?
what is function pointer?
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
Is it possible to initialize a variable at the time it was declared?