FBWiki : KeyPgOpPtrIndex

FBWiki :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Operator [] (Pointer index)


Returns a reference to memory offset from an address

Syntax:


Usage:
result = lhs [ rhs ]

Parameters:
lhs
The base address.
rhs
A signed offset from lhs.
T
Any data type.

Description:
This operator returns a reference to a value some distance in memory from a base address. It is essentially shorthand for "*(lhs + rhs)"; both do exactly the same thing. Like pointer arithmetic, any type of POINTER can be indexed except for an ANY POINTER. Also, like pointer arithmetic, it is up to the user to make sure meaningful data is being accessed.

Examples:
'' initialize a 5-element array
Dim array(4) As Integer = { 0, 1, 2, 3, 4 }

'' point to the first element
Dim p As Integer Ptr = @array(0)

'' use pointer indexing to output array elements
For index As Integer = 0 To 4
    Print p[index]
Next


Will give the output,

0 1 2 3 4


Differences from QB:

See also:

Back to Indexing Operators
Back to Operators

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.0



sf.net phatcode