Follow

This is illegal in C#:

short x = 1, y = 1;
short z = x + y;

1) Why?
2) Is the same true in C? Java?

@peterdrake I learned something new today, thanks for the puzzle.

@peterdrake
The plus operator will turn both into int, supposedly because it's faster as most processors don't work natively with smaller types, at least those that #csharp was designed to run on.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.