One plus one
12.08.2019
A little funny quiz I've came up with. Guess programming language:
- '1' + 1 = 11
- '1' + 1 = 2
- '1' + 1 = 50
- '1' + 1 = TypeError
Answers below
- Javascript. Press F12 in your browser (open dev tools console) and try for yourself
> '1' + 1
< "11"
- PHP
echo '1' + 1;
2
- C. '1' has char type, which is also an ASCII code of the symbol '1', which is 49. Plus one makes it 50.
printf("%d", '1' + 1);
50
- Python.
print '1' + 1;
TypeError: cannot concatenate 'str' and 'int' objects