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
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 |
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 |
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 |
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 |
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 |
Program to find the sum of digits of a given number until the sum becomes a single digit
write a program to gat the digt sum of a number (et. 15= >1+5=6)
write a programe to accept any two number and check the following condition using goto state ment.if a>b,print a & find whether it is even or odd and then print.and a<b,printb.find the sum digits of that number & then print.if a==b multiply 10 with a & add 20 with b store in c and then print
differentiate between const char *a; char *const a; and char const *a;
2 Answers College School Exams Tests, HCL, TCS,
How many data structures are there in c?
How to run c Program without using IDE of c. means if program made in notepad.then how to compile by command prompt.
Why do we use namespace feature?
What are pointers really good for, anyway?
#include<stdio.h> int fun(); int i; int main() { while(i) { fun(); main(); } printf("hello \n"); return 0; } int fun() { printf("hi"); } answer is hello.how??wat is tat while(i) mean?
can we change the default calling convention in c if yes than how.........?
write a “Hello World” program in “c” without using a semicolon?
Write a C program to check a number even or odd, without using any relational, arithmetic operator and any loops.