---
title: "FORTRAN constants, variables, library functions"
subject: "Computer Programming"
chapter: 11
key: "semester_1/computer_programming:fortran-constants-variables-library"
source: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-constants-variables-library
site: BCT Engineering
---

# FORTRAN constants, variables, library functions

Computer Programming · Chapter 11: Programming Language: FORTRAN

- Asked in: 2067 Asoj, 4 marks
- Video: [FORTRAN Constants and Variables](https://www.youtube.com/watch?v=L9kh8H1DJMc) — Dr. Reetu
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-constants-variables-library
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-11

## Question

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

## 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.

## Answer

#### 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.

| Function | Value |
|---|---|
| `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)`

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What does the real constant 1.5E3 mean?
   A. 15.3
   B. 1.5 x 10^3 = 1500.0
   C. 1.5 + 3
   D. 0.0015
   Answer: B. E3 means multiply by 10^3, so 1.5E3 = 1500.0. (Key point: Exponent form)

2. Which is a valid FORTRAN 77 variable name?
   A. 2SUM
   B. TOTAL
   C. A B
   D. X-1
   Answer: B. A name starts with a letter, has 1 to 6 letters or digits and no spaces or special characters; TOTAL is valid. (Key point: Variable names)

3. What does MOD(I,J) return?
   A. The quotient of I / J
   B. The remainder of I / J
   C. The larger of I and J
   D. The absolute value of I
   Answer: B. MOD is the remainder function, e.g. MOD(17,5) = 2. (Key point: Library functions)

## Related in Computer Programming

- [Constants and variables](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aconstants-and-variables) — Computer Programming, chapter 3
- [Advantages of using functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aadvantages-of-functions) — Computer Programming, chapter 6

## Related in other subjects

- [Penman equation and its variables](https://www.bctengineer.com/question.md?key=semester_5%2Fengineering_hydrology%3Apenman-equation-variables) — Engineering Hydrology, chapter 3
