007. Integer division truncates#

topic: Basics

int-trunc.f90 | | Godbolt Compiler Explorer logo | Fortran logo#
print *, 2+3, 2-3, 2*3, 2/3, 2/3.0, 2.0/3, 2**3
end
Output1#
           5          -1           6           0  0.666666687      0.666666687               8

2/3 = 0 in Fortran because the quotient of two integers is truncated to an integer. The quotient of an integer and a real is a real.



1

Compiled using GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 with no flags