A few more examples.
Pascal
program pointer_example;
var i : Integer;
ip : ^Integer; (* Pointer to integer; ^ is prefix *)
begin
i := 0;
(* Neither ISO 7185 Standard Pascal nor ISO 10206 Extended
Pascal describe a way to get a pointer to a variable, but
this is a common extension. See comments below. *)
ip := @i; (* Get a pointer to an integer; @ is prefix *)
ip^ := ip^ xor 1; (* Dereference is a postfix operator. *)
(* Also note that ^ is not used for any other purpose. *)
end.
Fortran
program pointerExample
implicit none
integer, pointer :: p1 ! p1 is a pointer to integer
integer, target :: t1 ! t1 is an integer target
! You can only take the address of a variable that has the "target"
! attribute. Fortran has very strict aliasing rules, and this signals
! that the variable may be aliased.
!
! This is kind of the opposite of the (now deprecated) "register"
! keyword in C, which is a signal that you cannot take the address
! of it, and it will never be the alias of another variable.
t1 = 1
p1=>t1 ! p1 points to t1
p1 = 2 ! Fortran has no pointer arithmetic, so there
! is no need for special "dereference" syntax.
end program pointerExample
BLISS
! BLISS is unusual in that the name of a variable denotes
! a pointer to it. If this sounds weird to you, consider that in
! C, the name of an array denotes a pointer to its first member.
!
! Note that BLISS only really has one "type": the machine word.
MODULE POINTERS (MAIN = CTRL) =
BEGIN
FORWARD ROUTINE
TEST;
ROUTINE TEST =
BEGIN
LOCAL
X,
Y;
! This assigns 1 to the variable X.
X = 1;
! This assigns the address of the variable X to the
! variable Y, with no explicit "reference" operator.
Y = X;
! If you want to assign the value in X to the variable Y,
! you need to explicitly dereference X.
X = .Y;
! Dereference on the lhs means assigning through a pointer.
! Store 2 in the memory location stored in Y.
.Y = 2;
END;
ELUDOM
a[b]
is*(a+b)
, which is*(b+a)
, which isb[a]
, so rather than(&x)[y]
one can writey[&x]
. $\endgroup$