When will I need to explicitly add 'L' or 'l' to a number ? I got from one mock exam that " long l = 100; is illegal ?! It works when I tired compiling . In relation to that .. char c = 100 -- works too ?! I thought that char only accept 'x' or '\uxxxx' as value ? What exactly is happening here ?
The mock exam is wrong. long myLong = 100; is valid. char c = 100; is also valid. 100 is an int, but since it is a constant, the compiler knows that it will fit into the char. Char is just an int type that takes values of 0 to 16535.