Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why is c++ weird?

Name: Eamon 2012-08-28 19:39

Why is this line ok:

long double x = (1 / sqrt(2));

but this one isn't:

long double x = (1 / 4);

?

Name: Anonymous 2012-08-31 13:56

C++ has type inference. It infers that sqrt returns a double so the whole expression is a double. The other one is an integer division because the compiler infers that both operands are int.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List