Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am learning Fortran because well, yeah, thought I'd learn it. However, I've found utterly no information on what the purpose of * is in print, read, etc:

program main

    print *, "Hello, world!"

end program main

What is the purpose of this *? I've done some research however I don't think I understand it properly, I don't want to carry on learning until I actually know the point of *.

From what I've managed to find I think that it's some sort of format specifier, however, I don't understand what that means and I have no idea if I'm even correct. All the tutorials I've found just tell me what to write to print to the console but not what * actually means.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
336 views
Welcome To Ask or Share your Answers For Others

1 Answer

You are correct in that it is a format specifier.

There's a page on Wikibooks to do with IO and that states:

The second * specifies the format the user wants the number read with

when talking about the read statement. This applies to the write and print statements too.

For fixed point reals: Fw.d; w is the total number of spaces alloted for the number, and d is the number of decimal places.

And the example they give is

REAL :: A
READ(*,'(F5.2)') A

which reads a real number with 2 digits before and after the decimal point. So if you were printing a real number you'd use:

PRINT '(F5.2)', A

to get the rounded output.

In your example you're just printing text so there's no special formatting to do. Also if you leave the format specifier as * it will apply the default formatting to reals etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...