This wiki is out of date, use the continuation of this wiki instead

Pointer

From FenixWiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 22:37, 29 May 2007 (edit)
Sandman (Talk | contribs)
m
← Previous diff
Revision as of 18:48, 17 May 2008 (edit) (undo)
85.144.194.29 (Talk)
(Concept - Pointers can only point to strong datatypes, info about how to go about a struct pointer.)
Next diff →
Line 14: Line 14:
=== Concept === === Concept ===
-'''Pointer'''s, are used to point to a location in [[memory]]. It uses 32 [[bit]]s (4 [[byte]]s) so it can map 4GB of memory into bytes. '''Pointer'''s can point to any [[datatype]]: [[int]]s, [[short]]s, [[string]]s or even usermade datatypes.+'''Pointer'''s, are used to point to a location in [[memory]]. It uses 32 [[bit]]s (4 [[byte]]s) so it can map 4GB of memory into bytes. '''Pointer'''s can point to any strong [[datatype]]: [[int]]s, [[short]]s, [[string]]s or even usermade datatypes. In order to point to a weak datatype like a struct, the struct would have to encapsulated in a user defined datatype.
== Example == == Example ==

Revision as of 18:48, 17 May 2008


Contents

Definition

Statement

Declaration of a pointer:
<datatype> POINTER <pointername>
<datatype> * <pointername>

Assignment of a value to the location pointed to:
POINTER <pointername> = <value>;
* <pointername> = <value>;

Concept

Pointers, are used to point to a location in memory. It uses 32 bits (4 bytes) so it can map 4GB of memory into bytes. Pointers can point to any strong datatype: ints, shorts, strings or even usermade datatypes. In order to point to a weak datatype like a struct, the struct would have to encapsulated in a user defined datatype.

Example

Program pointers;
Private
    int my_int;
    int pointer my_int_pointer;
Begin

    my_int_pointer = &my_int;

    my_int = 3;
    say(my_int);
    say(*my_int_pointer);
  
    *my_int_pointer = 4;
    say(my_int);
    say(*my_int_pointer);

    Repeat
        frame;
    Until(key(_esc))

End

The & (offset) operator, when used with pointers, returns a void pointer to a variable. In the example it returns an int pointer to the variable my_int. The * (pointer) operator, when used with pointers, makes it so the pointer variable is not accessed, but the variable it's pointing to. In the example it changes access from my_int_pointer to my_int.

Personal tools