Skip to main content

Data types in FORTRAN

Short answer

Standard data types: INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, CHARACTER. Implicit typing makes variables starting with I–N integer, others real; explicit declarations override this and must come before executable statements.

What are the different data types in FORTRAN?

Every variable and constant in FORTRAN has a data type, which decides its storage and the operations allowed. The standard types are:

TypeDeclarationMeaning and example
INTEGERINTEGER N, COUNTWhole numbers, no decimal point: 25, -7
REALREAL X, AREANumbers with fractional part (single precision, about 7 digits): 3.14, -0.5, 2.5E3
DOUBLE PRECISIONDOUBLE PRECISION DReal numbers with about twice the digits (about 15): 3.14159265358979D0
COMPLEXCOMPLEX ZPair of reals (real, imaginary): (2.0, -3.5)
LOGICALLOGICAL FLAGOnly .TRUE. or .FALSE.
CHARACTERCHARACTER*10 NAMEText; *10 gives the length: 'NEPAL'

Implicit typing. If a variable is not declared, its type is decided by its first letter: names starting with I, J, K, L, M or N are INTEGER, all other letters give REAL. IMPLICIT NONE (a common extension) turns this off and forces declarations. Declarations must come before executable statements.

      INTEGER I, N
      REAL X
      LOGICAL OK
      CHARACTER*8 CITY
      CITY = 'POKHARA'
      OK = .TRUE.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 11 questions →