---
title: "Two dimensional arrays in FORTRAN"
subject: "Computer Programming"
chapter: 11
key: "semester_1/computer_programming:fortran-2d-array-syntax"
source: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-2d-array-syntax
site: BCT Engineering
---

# Two dimensional arrays in FORTRAN

Computer Programming · Chapter 11: Programming Language: FORTRAN

- Asked in: 2069 Asar, 4 marks
- Video: [[Fortran Tuto 9] Dimension Arrays](https://www.youtube.com/watch?v=dvMnZEt8maE) — Cyprien Rusu
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/fortran-2d-array-syntax
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-11

## Question

What is the syntax of two dimensional arrays in FORTRAN? Explain with example.

## Short answer

A two-dimensional array is declared as type name(rows, columns) or DIMENSION name(rows, cols), e.g., INTEGER A(3,4) for 3 rows and 4 columns. Subscripts start from 1 (by default) and storage is column-major; an element is referenced as A(i,j).

## Answer

A two dimensional array is a table of rows and columns. It must be declared before use, either with a type statement or with `DIMENSION`.

**Syntax**
```fortran
      type name(rows, columns)
      DIMENSION name(rows, columns)
```
Examples: `INTEGER A(3,4)` (3 rows, 4 columns, 12 elements) and `REAL B(2,2)`.

- Subscripts start from 1 by default: A(1,1) is the first element. Other bounds can be given as `A(0:2, 0:3)`.
- An element is written `A(i,j)`, row i and column j.
- FORTRAN stores arrays in **column-major** order (the first subscript changes fastest).
- FORTRAN 77 allows up to seven dimensions.
- The subscripts can be integer expressions, and nested DO loops or nested implied DO are used to process them.

**Example:** read and print a 2×3 array

```fortran
      PROGRAM ARR2D
      INTEGER A(2,3), I, J
      READ *, ((A(I,J), J = 1, 3), I = 1, 2)
      DO 10 I = 1, 2
         PRINT *, (A(I,J), J = 1, 3)
   10 CONTINUE
      STOP
      END
```
For input `1 2 3 4 5 6` it prints `1 2 3` and then `4 5 6`.

## Check yourself

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

1. What does INTEGER A(3,4) declare?
   A. 3 rows, 4 columns, 12 elements
   B. 4 rows, 3 columns, 7 elements
   C. A 3 x 4 text
   D. 12 rows
   Answer: A. The first subscript is rows and the second columns: 3 x 4 = 12 elements. (Key point: Declaration)

2. In what order does FORTRAN store arrays in memory?
   A. Row-major
   B. Column-major, the first subscript changing fastest
   C. Random
   D. Diagonal
   Answer: B. FORTRAN is column-major. (Key point: Storage order)

3. In A(i,j), what do i and j stand for?
   A. Column i, row j
   B. Row i, column j
   C. Row i, depth j
   D. Both rows
   Answer: B. A(i,j) is the element in row i and column j. (Key point: Element notation)

## Related in Computer Programming

- [Formatted I/O in FORTRAN with syntax](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-formatted-io-syntax) — Computer Programming, chapter 11
- [Array overflow/underflow; add two arrays](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aarray-overflow-underflow-add) — Computer Programming, chapter 7
- [Sum of two matrices in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-matrix-sum) — Computer Programming, chapter 11
- [Creating 1D and 2D arrays](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aone-two-dim-arrays-created) — Computer Programming, chapter 7, asked 2×
- [Add and subtract matrices in FORTRAN](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afortran-matrix-add-subtract) — Computer Programming, chapter 11
- [Significance of arrays; multiply 3×3 matrices](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aarray-significance-multiply-matrices) — Computer Programming, chapter 7

## Related in other subjects

- [Antenna arrays and two-element expression](https://www.bctengineer.com/question.md?key=semester_6%2Fpropagation_and_antenna%3Adefine-array-two-isotropic) — Propagation and Antenna, chapter 2
- [Derive two-dimensional heat equation](https://www.bctengineer.com/question.md?key=semester_4%2Fapplied_mathematics%3Aheat-eq-2d-derive) — Applied Mathematics, chapter 3, asked 2×
- [Need for arrays and two-element patterns](https://www.bctengineer.com/question.md?key=semester_6%2Fpropagation_and_antenna%3Aarray-need-two-isotropic-radiators) — Propagation and Antenna, chapter 2
- [OpenGL syntax: 3D vertex](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aopengl-3d-float-vertex-syntax) — Computer Graphics, chapter 9
