问题描述
这是一个初学者的问题,但我还没有找到一个COM prehensive答案。
This is a beginners question but I haven't found a comprehensive answer.
有什么区别(如果有的话)以下的声明?
What are the differences (if any) of the following declarations?
CHARACTER(5) :: a
CHARACTER, DIMENSION (5) :: b
CHARACTER(LEN=5) :: c
CHARACTER :: d(5)
CHARACTER :: e*5
和:都是这些声明可能与其他类型,例如的实
And: are all of these declarations possible with other types, e.g REAL
?
推荐答案
无论类型,<类型>,尺寸(5):: b
和<&型GT; :: B(5)
是相同的,并且表示长度阵列5
。 <&型GT;
可以是如字符
,整数
,真正
,逻辑
等
Regardless of the type, <type>,dimension(5) :: b
and <type> :: b(5)
are identical and denote an array of length 5
. <type>
can be e.g. character
, integer
, real
, logical
, etc.
字符(5)
是字符的短手(LEN = 5)
和声明的字符串长度 5
。如果省略的长度,它被假定为上。 字符:: D(5)
是五个长度为1的字符串数组。
character(5)
is a short-hand of character(len=5)
and declares a string of length 5
. If the length is omitted, it is assumed to be on. character :: d(5)
is an array of five length-1 strings.
字符:: E * 5
是一个较旧的变体,以指定字符串的长度。
character :: e*5
is an older variant to specify the string length.
LEN
是固有的字符串(且不再为SENCE花车例如)。您可以指定自己的派生类型有一个长度 LEN
,虽然(参数化派生类型)。对于整数和浮点数(及其他),你可以以类似的方式指定样
的变量。
len
is intrinsic to strings (and makes no sence for e.g. floats). You can specify your own derived types to have an length len
, though ("Parameterized derived types"). For integers and floats (and some others) you can specify the kind
of the variable in a similar way.
有关详细信息,请参考,通道。 4.4.3.2的字符类型说明符的。
For details consult the Fortran 2008 Standard, Ch. 4.4.3.2 "Character type specifier".
这篇关于在FORTRAN数组声明对于初学者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!