Skip to content
Variables and Types
step 1/5

Reading — step 1 of 5

Learn

~1 min readBasics

Modern Fortran requires explicit typing — start every program with implicit none to enforce it:

program demo
    implicit none
    integer :: age
    real :: pi
    character(len=20) :: name
    logical :: active

    age = 36
    pi = 3.14159
    name = "Ada"
    active = .true.
end program demo

Declarations come BEFORE executable statements. The :: separates type info from name.

Numeric types:

  • integer (default 4 bytes) — integer(kind=8) for 64-bit
  • real (default 4 bytes / single precision) — real(kind=8) or double precision for 64-bit
  • complex — built-in complex numbers (re, im)

Booleans use .true. / .false. (with the dots).

Strings are fixed-length: character(len=10) holds exactly 10 chars (padded with spaces). Allocatable strings: character(len=:), allocatable :: s.

Arithmetic operators: + - * / ** (the ** is exponent, not pointer-deref).

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…