Multiple choice technology programming languages

What would be the output of the following program? main() { unsigned char i = 0x80; printf("\n%d", i<<1); }

  1. 0

  2. 256

  3. 100

  4. None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The hexadecimal value 0x80 equals 128 in decimal. When you left-shift this by 1 position (i<<1), you multiply by 2, resulting in 256. The printf uses %d which prints the integer value, and unsigned char is promoted to int in the expression, so 256 fits within the output.