Skip to content

Pointers. Parents of web links


  1. by value: we pass the value by copying it to another variable, avoiding to affect the original one;
  2. by reference: we assign the same original variable's address to another, obtaining two different labels for same memory location (even if we pass external x to internal x, because internal is local);
  3. by pointer: we pass a variable containing the address to another one.

Notice that local variable x is declared as pointer to integer, and not with mypinteger but with pinteger only.

Indeed they're the same, because the first is defined by us, while the second is predefined in FreePascal language set.

Pinteger is a pointer to integer, by default [pchar for chars, and so on].

This explains the difference you'll find in code, even if it will work and compile without errors.

You can imagine the caret ^ like an arrow -->, so that if it precedes a type means pointer to type, if it follows a variable then means var pointing something.

Finally notice that nobody forbids you to use directly the ^integer expression every time you need to declare a pointer to integer: in facts you'll find in code a commented procedure

//procedure SquareByPointer2(x: ^integer); // int* x in c++

which is perfectly interchangeable with the previous SquareByPointer procedure.

We're done: as always we recommend to test code, even by changing it to understand the new consequences.

Whole project can be downloaded from here. In next page you'll see the code used in project.