1

This is something they included as part of my course, just wondering why it does this and what they were trying to show with it but can't seem to figure it out. Is it some sort of principle when trying to concatenate chars to numbers? Am I right in assuming that 'z' is a char because it's in single quotes here?

Is it some sort of error because you shouldn't write stuff like this? Thanks in advance!

imsan
  • 359
  • 4
  • 17

2 Answers2

3

z is char value, char is basically a number. z will be implicitly converted to int (z code is 122), that's why 3 + 'z' + 4 == 129. It will be converted to int because in statement 3 + 'z' 3 is int, so result of addition will be also int.

ingvar
  • 4,169
  • 4
  • 16
  • 29
0

In C# char is a 16 bit numeric value which represents a unicode character. So in your case z is implicitly evaluated as 122. So 3 + 122 + 4 equals 129.

Alex
  • 1,433
  • 9
  • 18