main()
{
int a=5;
printf(?%d,%d,%d\n?,a,a< <2,a>>2);
}
Answer: 5,20,1 please explain this code in detail

Answer Posted / manishsoni

#include<stdio.h>
#include<conio.h>
int main()
{
int a=5;
printf("%d,%d,%d\n",a,a<<2,a>>2);
getch();
return 0;
}


the ans is 5,20,1
How this ans is :
(1) a=5
(2) a=5
____________________
In digit |In binary|
__________|_________|
5 |101 |
__________|_________|
5<<2 |101<<2 |
__________|_________|
20 |10100 |
__________|_________|


(3)

____________________
In digit |In binary|
__________|_________|
5 |101 |
__________|_________|
5>>2 |101>>2 |
__________|_________|
1 |1 |
__________|_________|

----------------------------------------------------------|
<< is left shift operator and behave as : |
it shift the value left side and attached the 0 with right|
side. |
----------------------------------------------------------|
>> is right shift operator and behave as: |
it shift the value right side and attached the 0 with left|
side. |
----------------------------------------------------------

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is operator promotion?

623


Explain what is a stream?

603


Is c# a good language?

600


Tell me with an example the self-referential structure?

558


What is a newline escape sequence?

659






What is the use of a static variable in c?

585


What are the different types of endless loops?

612


What is the difference between declaring a variable and defining a variable?

710


can we have joblib in a proc ?

1650


List the different types of c tokens?

614


Explain how can you restore a redirected standard stream?

584


What is the value of a[3] if integer a[] = {5,4,3,2,1}?

660


Explain what is the advantage of a random access file?

650


How can I find out if there are characters available for reading?

633


What are the disadvantages of external storage class?

582