Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
fun main() {
val word = "cat"
println(word[0])
println(word[0] + 1)
}c d
- Expecting
c c1: treatingword[0]as a string. It is aChar, and adding1to aChargives the next character,'d'. - Expecting
c 100: thinking aCharturns into its number.'c' + 1is still aChar; its code is read with.code.
- What does
println(word[0].code)print? - What does
println("" + word[0] + 1)print, and why does it differ?