Casting and Ranges of Variables

AP Computer Science A· difficulty 3/5

char c = '5';
int n = c - '0';
System.out.println(n);

What is printed?

  • A

    53

  • B

    5

    check_circle
  • C

    0

  • D

    5.0

Explanation

The Unicode value of '5' is 53 and of '0' is 48; 53 - 48 yields 5, a common way to convert a digit char to its int.

Want 10 more like this — adaptive to your weak spots?

Related questions