What is the output of int a = 10; printf("%d", a << 2);?
Question
What is the output of int a = 10; printf("%d", a << 2);?
Solution
The output of the given code will be 40.
Here's the step by step explanation:
-
The code
int a = 10;is declaring an integer variable 'a' and assigning it the value 10. In binary, 10 is represented as 1010. -
The '<<' operator is a bitwise operator that shifts the bits of the number to the left by the number of bits specified. In this case,
a << 2shifts the bits of 'a' 2 places to the left. -
When we shift the bits of 10 (1010 in binary) 2 places to the left, we get 101000, which is the binary representation of 40.
-
Finally,
printf("%d", a << 2);prints the result ofa << 2, which is 40.
Similar Questions
What is the result of printf("%d", 1 && 2);?
What will be the output of the following code snippet?123456#include <stdio.h> int main() { int a = 10, b = 4; printf("%d", a - b * 2); }
What is the output of the following piece of code?int i;i = 10;while (i < 20){ printf("%d", i % 2); i++;}
What will be the output of the following code snippet?printf("%d", 5 == 5);
What will be the output of following program?main( ){int k, num = 30 ;k = ( num > 5 ? ( num <= 10 ? 100 : 200 ) : 500 ) ;printf ( "\n%d", num ) ;}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.