Knowee
Questions
Features
Study Tools

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);?

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given code will be 40.

Here's the step by step explanation:

  1. The code int a = 10; is declaring an integer variable 'a' and assigning it the value 10. In binary, 10 is represented as 1010.

  2. 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 << 2 shifts the bits of 'a' 2 places to the left.

  3. 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.

  4. Finally, printf("%d", a << 2); prints the result of a << 2, which is 40.

This problem has been solved

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 ) ;}

1/3

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.