Skip to content
Paul Squires edited this page Oct 19, 2026 · 2 revisions

Home › Memory Functions › Peek

Peek

Returns a reference to the value at an address, as a byte or as a given type.

Syntax

Declare Function Peek ( ByVal address As Any Ptr ) ByRef As UByte
Declare Function Peek ( datatype, ByVal address As Any Ptr ) ByRef As datatype

Parameters

  • address
  • datatype

Description

This procedure returns a reference to the value in memory given by a memory address, and is equivalent to:

*cast(ubyte ptr, address)

or

*cast(datatype ptr, address)

thus this keyword can also be used to assign a value to a memory location, similarly to Poke.

Note: When using Peek, the -exx compiler option does not add code for null-pointer checking (no nullity test on the value of address).

Remarks

Usage

Peek( [ datatype, ] address )

Differences from QB

  • Peek did not support the datatype parameter in QB, and could only return individual bytes. Peek returns a reference in FB, so can be used to set the memory contents of the address, like with Operator * (Value Of). DEF SEG isn't needed anymore because the address space is 32-bit flat in FreeBASIC.

See also

Examples

Dim i As Integer, p As Integer Ptr

p = @i

Poke Integer, p, 420

Print Peek(Integer, p)

will produce the output:

420

Category: Memory Functions
Kind: function


Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.

Clone this wiki locally