# System Functions

MEM( ) | Return Memory Value

## Formats

1. Get Address of String: | MEM(var$[,ERR=stmtref])
2. Read Memory, 2 Bytes: | MEM(address[,ERR=stmtref])
3. Read Memory, 'n' Bytes: | MEM(address,bytes[,ERR=stmtref])
4. Change Memory: | MEM(address,val$[,ERR=stmtref])

Where:

var$ | Name of string variable whose address you wish to obtain.
address | Number of bytes to return (numeric expression).
val$ | Value you wish to write (string expression).
stmtref | Program line number or statement label to which to transfer control should an error occur.

## Returns

Memory location and/or value.

#### Note:
This function is mainly for use with external functions; i.e. using the DLL( ) and DLX( ) functions.

## Description

The MEM( ) function provides direct access to memory locations through the use of pointers. The return value is dependent on the format used:

Format 1 | Returns a numeric value with the address of your string variable.
Format 2 | Returns a numeric value that has the contents of a word (16 bits) of memory. The value returned is a binary value (integer in two's complement format).
Format 3 | Returns a string consisting of the data at the address specified for the specified number of bytes. If the number of bytes specified is 0 (zero), the function returns all data starting at the specified address up to the first NULL byte. This is handy when used to retrieve null terminated strings, which are a common format used with system calls.
Format 4 | Copies your character string value to the address given. The function returns the value of the string val$.

Where possible (primarily Windows), the system performs address validation and returns an Error #41: Invalid integer encountered (range error or non-integer) for an invalid memory location. If address validation is not possible, use of an invalid address may cause the application to abort.