Menu Close

READ(*,*) & WRITE(*,*) Statement – FORTRAN

In Fortran, READ(*,*) and WRITE(*,*) are input/output statements that allow you to read data from and write data to the standard input/output channels (keyboard/output screen).

Here’s a simple explanation of these statements:

1. READ(*,*)

This statement is used to read input data from the standard input (usually the keyboard) into variables.

  • The * in the first position denotes that the input is coming from the default input channel (such as keyboard)
  • The second * denotes that the format of the input is unspecified. It means that the program reads the input as a list of values and assigns them to the specified variables.

Example:

In the below code, the program will read an integer value from the standard input and assign it to the variable age.

INTEGER :: age
READ(*,*) age

2.WRITE(*,*)

This statement is used to write output data to the standard output (usually the console or terminal).

  • The * in the first position indicates that the output is directed to the default output channel (such as your screen).
  • The second * indicates that the format of the output is unspecified. It means that the program writes the values of the specified variables as a list to the standard output.

Example:

In the below code, the program will write a message and the value of the variable temperature to the standard output, displaying something like: “The current temperature is: 25.5”.

REAL :: temperature = 25.5
WRITE(*,*) "The current temperature is:", temperature

More Related Stuff