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

Answers were Sorted based on User's Feedback



main() { int a=5; printf(?%d,%d,%d\n?,a,a< <2,a>>2); } Answer: 5,20,1 please explai..

Answer / neha tibrewal ritm jaipur

firstly value of a is printed. value of a=5, so 5 is printed.
Now, a<<2 means 5<<2 i.e 5 is left shifted by 2.
in binary 5= 101
101<<2= 10100 and decimal value of 10100=20.
so, a<<2=20.
again, a>>2 means 5>>2 i.e 5 is right shifted by 2.
101>>2= 001 and decimal value of 1=1.
so, a>>2=1.

Is This Answer Correct ?    3 Yes 0 No

main() { int a=5; printf(?%d,%d,%d\n?,a,a< <2,a>>2); } Answer: 5,20,1 please explai..

Answer / sathish

go through right shift & left shift operator function.

Ex: a<<2 = 5<<2 = 00000101(in binary)<<2 = 00010100(in
binary) = 20(in decimal)

Is This Answer Correct ?    2 Yes 2 No

main() { int a=5; printf(?%d,%d,%d\n?,a,a< <2,a>>2); } Answer: 5,20,1 please explai..

Answer / ganeshuit

hey please tell me why there is ? sign in printf().and what
is use of it?

Is This Answer Correct ?    0 Yes 0 No

main() { int a=5; printf(?%d,%d,%d\n?,a,a< <2,a>>2); } Answer: 5,20,1 please explai..

Answer / 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

main() { int a=5; printf(?%d,%d,%d\n?,a,a< <2,a>>2); } Answer: 5,20,1 please explai..

Answer / saikumar

main()
{
int a=5;
printf("%d,%d,%d\n",a,a<<5,a>>2);
}
explanation:in the above program already we assinged a value is 5.
in the printf statement a is 5
and a<<2 it means 'a' leftshift 2 it should converted in to binary form .first we take 5 is in the binary form is 101.
and next we take 2 is in the binary form 010.
we have to shift the 5 to left side of 2 terms .
101<<010=10100=20.
101>>010=001=1.
output:
5
20
1

Is This Answer Correct ?    0 Yes 0 No

main() { int a=5; printf(?%d,%d,%d\n?,a,a< <2,a>>2); } Answer: 5,20,1 please explai..

Answer / k siva sindhu

1

Is This Answer Correct ?    2 Yes 3 No

Post New Answer

More C Interview Questions

how to set Nth bit of a variable?

1 Answers  


WHICH TYPE OF JOBS WE GET BY WRITING GROUPS .WHEN THE EXAMS CONDUCTED IS THIS EXAMS ARE CONDUCTED EVERY YEAR OR NOT.PLS TELL ME THE ANSWER

0 Answers  


How do you convert strings to numbers in C?

0 Answers  


what is the purpose of the code, and is there any problem with the code? int f( int n, int l, int r ) { return (n << l) >> r; }

2 Answers   Google,


A MobileNumber is a VIP number if it satisfy the following conditions. The operator should be Vodafone. Atleast one 0 (Zero) should be exist in mobile number. The number should not end with 8. The single digit sum of all the digits in the number should be equal to 9. For example if the number is 9876543210, the sum is 9+8+7+...+1+0 = 45. Sum of 4+5 = 9. Write a method: private boolean isVIPMobileNumber(String mobileNum, String operator) mobileNum phone number operator mobile operator as bsnl, Vodafone

1 Answers  






Write a program to enter the name and age. If age>28 then find salary categories. if age<28 then find that you are gaduate or not.

1 Answers  


how to write a c program to print list of fruits in alpabetical order?

0 Answers  


i want to switch my career from quailty assurance engineering to development kindly guide me from which programming language its better for me to start plz refer some courses or certifications too i have an experience of 1.5 yrs in QA field.Kindly guide me

0 Answers   Microsoft,


how can make variable not in registers

1 Answers   TCS,


What would happen to X in this expression: X += 15; (assuming the value of X is 5)

0 Answers  


What is the difference between a function and a method in c?

0 Answers  


#define MAX 3 main() { printf("MAX = %d ",MAX ); #undef MAX #ifdef MAX printf("Vector Institute”); #endif }

1 Answers  


Categories