Types: integer real complex logical character

Contents
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

Related articles
Fortran
Fortran course: zero to hero in 50 lessons
What is Fortran and where it runs
Install gfortran
Your first program
Program structure
Types: integer real complex logical character
Kind parameters
Operators
Conditions
DO loops
Arrays
Array sections
Character strings
Formatted IO
Files
Subroutines and functions
Modules
USE with ONLY
INTENT
OPTIONAL and PRESENT
Explicit interfaces
Derived types
Type-bound procedures
Object orientation
Operator overloading
Finalization
Allocatable arrays
Pointers in Fortran
DO CONCURRENT
Coarrays
OpenMP basics
Namelists
IEEE arithmetic
Intrinsic matrix math
Random numbers
String tools
Command-line arguments
Environment variables
error stop
Testing
Build with gfortran and make
Debugging
C interoperability
From fixed form to free form
Numeric models
Performance
Modern Fortran tour: 2008, 2018, 2023
Capstone: stats tool
Capstone: 1D heat equation
Style guide
Hero roadmap: the whole course on one page
Install gfortran on Windows 11
Install gfortran on Ubuntu
Install gfortran on Rocky Linux
Install gfortran on macOS
Install gfortran on FreeBSD
Fortran in Docker

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: