Why must a short be converted to an int before arithmetic operations in C and C++?

If we look at the Rationale for International Standard—Programming Languages—C in section 6.3.1.8 Usual arithmetic conversions it says (emphasis mine going forward): The rules in the Standard for these conversions are slight modifications of those in K&R: the modifications accommodate the added types and the value preserving rules. Explicit license was added to perform calculations … Read more

The shortest java code [closed]

Almost correct: System.out.println((int)Math.signum(input.nextInt() – input.nextInt()); “Almost” due to possible integer overlow. Also your longer code might actually be faster (signum() operaton on floating-point numbers), not to mention more readable.