Skip to main content

FORTRAN constants, variables, library functions

Short answer

Constants are fixed values: integer (25), real (3.14, 1.5E3), double precision (2.5D0), complex ((1.0,2.0)), logical (.TRUE., .FALSE.), character ('NEPAL'), named (PARAMETER). Variables are named memory locations, typed explicitly or by implicit convention (I-N integer, else real). Intrinsic functions include SQRT, ABS, SIN, EXP, LOG, MOD, INT, MAX, etc.

What are FORTRAN's constants, variables and library functions? Explain.

Constants

A constant is a fixed value that does not change during execution.

  • Integer: 25, -4 (no decimal point).
  • Real: 3.14, -0.5, 1.5E3 (exponent form = 1500.0).
  • Double precision: 2.5D0.
  • Complex: (1.0, 2.0).
  • Logical: .TRUE., .FALSE.
  • Character: 'NEPAL' in single quotes.
  • Named constant: PARAMETER (PI = 3.14159).

Variables

A variable is a named memory location whose value may change. In FORTRAN 77 a name has 1 to 6 letters or digits (more in newer compilers), starts with a letter, and has no spaces or special characters. Its type is declared (INTEGER N) or taken from the first letter (I–N integer, others real).

Library (intrinsic) functions

Built-in functions that are called by name with arguments.

FunctionValue
SQRT(X)square root
ABS(X)absolute value
SIN(X), COS(X), TAN(X)trigonometric (X in radians)
EXP(X)e to the power X
LOG(X), LOG10(X)natural and common logarithm
MOD(I,J)remainder of I / J
INT(X), NINT(X)truncate / round to integer
FLOAT(I), REAL(I)integer to real
MAX(A,B,...), MIN(A,B,...)largest / smallest

Example: Y = SQRT(ABS(X)) + SIN(0.5)

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 11 questions →