Why a result of a division is automatically int in C#? -
i have line:
console.writeline((double)(1 / 4)));
which outputs: 0
.
i debugged it, , compiler treating 1 / 4
0:
so understand it, compiler treats 1 / 4
int
. why?
note: when write line:
console.writeline((double)1 / 4));
it outputs: 0.25
.
because 1
, 4
both int
s. there no reason compiler make type-conversions. run sample , see outputs:
int x = 1, y = 4; console.writeline(x / y); double xx = 1; console.writeline(xx / y); double yy = 4; console.writeline(x / yy);
Comments
Post a Comment