1! Copyright 2019-2021 Free Software Foundation, Inc.
2!
3! This program is free software; you can redistribute it and/or modify
4! it under the terms of the GNU General Public License as published by
5! the Free Software Foundation; either version 3 of the License, or
6! (at your option) any later version.
7!
8! This program is distributed in the hope that it will be useful,
9! but WITHOUT ANY WARRANTY; without even the implied warranty of
10! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11! GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License
14! along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16program pointers
17
18  type :: two
19    integer, allocatable :: ivla1 (:)
20    integer, allocatable :: ivla2 (:, :)
21  end type two
22
23  logical, target :: logv
24  complex, target :: comv
25  character, target :: charv
26  character (len=3), target :: chara
27  integer, target :: intv
28  integer, target, dimension (10,2) :: inta
29  real, target :: realv
30  type(two), target :: twov
31
32  logical, pointer :: logp
33  complex, pointer :: comp
34  character, pointer :: charp
35  character (len=3), pointer :: charap
36  integer, pointer :: intp
37  integer, pointer, dimension (:,:) :: intap
38  real, pointer :: realp
39  type(two), pointer :: twop
40
41  nullify (logp)
42  nullify (comp)
43  nullify (charp)
44  nullify (charap)
45  nullify (intp)
46  nullify (intap)
47  nullify (realp)
48  nullify (twop)
49
50  logp => logv    ! Before pointer assignment
51  comp => comv
52  charp => charv
53  charap => chara
54  intp => intv
55  intap => inta
56  realp => realv
57  twop => twov
58
59  logv = associated(logp)     ! Before value assignment
60  comv = cmplx(1,2)
61  charv = "a"
62  chara = "abc"
63  intv = 10
64  inta(:,:) = 1
65  inta(3,1) = 3
66  realv = 3.14
67
68  allocate (twov%ivla1(3))
69  allocate (twov%ivla2(2,2))
70  twov%ivla1(1) = 11
71  twov%ivla1(2) = 12
72  twov%ivla1(3) = 13
73  twov%ivla2(1,1) = 211
74  twov%ivla2(2,1) = 221
75  twov%ivla2(1,2) = 212
76  twov%ivla2(2,2) = 222
77
78  intv = intv + 1 ! After value assignment
79
80end program pointers
81