Types: integer real complex logical character
| Integers | |
| Reals | |
| Complex | |
| Logical and character |
Integers
Integer values store whole numbers: counters, sizes, and indexes.
Declare the name first with the integer type, then assign with a plain equals sign.
program intdemo
implicit none
integer :: count
count = 42
print *, "count =", count
end program intdemo
Reals
Real values store fractional numbers: measurements, coordinates, and physical constants.
Always write a decimal point for real literals so the compiler treats them as real and not integer.
program realdemo
implicit none
real :: temp
temp = 36.6
print *, "temp =", temp
end program realdemo
Complex
Complex values store pairs of real parts for wave math, signals, and electrical models.
Build them from two reals in parentheses, with the real part first and the imaginary part second.
program cxdemo
implicit none
complex :: z
z = (1.0, 2.0)
print *, "z =", z
end program cxdemo
Logical and character
Logical values store truth with .true. and .false., while character values store text of fixed length.
Choose character with len for names and messages, and logical for flags that control branches and loops.
program mixdemo
implicit none
logical :: ready
character(len=20) :: city
ready = .true.
city = "Oslo"
print *, ready, city
end program mixdemo
Next: Kind parameters
Article author: Arthur Isaev