{{fbdoc item="title" value="Operator [] (Pointer index)"}}----
Returns a reference to memory offset from an address

{{fbdoc item="syntax"}}##
	[[KeyPgDeclare|declare]] [[KeyPgOperator|operator]] **[]** ( [[KeyPgByref|byref]] //lhs// [[KeyPgAs|as]] //T// [[KeyPgPtr|pointer]], [[KeyPgByref|byref]] //rhs// [[KeyPgAs|as]] [[KeyPgInteger|integer]] ) [[KeyPgByrefFunction|byref]] [[KeyPgAs|as]] //T//
##

{{fbdoc item="usage"}}##
	//result// = //lhs// **[** //rhs// **]**
##
{{fbdoc item="param"}}
	##//lhs//##
		The base address.
	##//rhs//##
		A signed offset from ##//lhs//##.
	##//T//##
		Any data type.

{{fbdoc item="desc"}}
	This operator returns a reference to a value some distance in memory from a base address. It is essentially shorthand for "##[[KeyPgOpValueOf|*]](//lhs// [[KeyPgOpAdd|+]] //rhs//)##" because the reference can be thought of as a pointer having as value the memory location "##(//lhs// [[KeyPgOpAdd|+]] //rhs//)##", and which is implicitly dereferenced; both do exactly the same thing.
	Like pointer arithmetic, any type of ##[[KeyPgPtr|Pointer]]## can be indexed except for an ##[[KeyPgAny|Any]]## ##[[KeyPgPtr|Pointer]]##. Also, like pointer arithmetic, it is up to the user to make sure meaningful data is being accessed.
	
	When indexing a '2-dimensional' pointer (i.e. a ##//T// Ptr Ptr##), the first (leftmost) index is applied before the second: For example, ##//Pt//[//I1//][//I2//]## = ##*(//Pt//[//I1//] + //I2//)## = ##*(*(//Pt// + //I1//) + //I2//)##
	In general, when using an '//n//-dimensional' pointer: ##//Pt//[//I1//][//I2//].....[//In//]##, the index order (from left to right) corresponds to the dereferencing order.
	
	This operator must not be used in case of null pointer because reference is undefined (inducing runtime error).
	Otherwise, the user must ensure that the offset value (##//rhs//##) is in a range that allows an access to valid memory. Outside this range, results are undefined.
	
	This operator can be overloaded for user-defined types as a member ##[[KeyPgOperator|Operator]]## using the appropriate syntax.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/operator/pointer-index.bas"}}%%(freebasic)
'' 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
print
%%

	Will give the output,

%% 0 1 2 3 4
%%

{{fbdoc item="diff"}}
	- New to ""FreeBASIC""

{{fbdoc item="see"}}
	- [[ProPgPtrArithmetic|Pointer Arithmetic]]
	- ##[[KeyPgOpValueOf|Operator * (Value of)]]##
	- ##{{fbdoc item="keyword" value="KeyPgOpStringIndex|Operator [] (String index)"}}##
	- ##[[KeyPgOpArrayIndex|Operator () (Array index)]]##
	- ##[[KeyPgOpAdd|Operator + (Add)]]##
	- ##[[KeyPgOpSubtract|Operator - (Subtract)]]##
	- [[CatPgOpPoint|Pointer Operators]]

{{fbdoc item="back" value="CatPgOpIndexing|Indexing Operators"}}{{fbdoc item="back" value="CatPgOperators|Operators"}}