Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pointers

Status
Not open for further replies.

peterworth

Programmer
Aug 18, 2004
80
GB
is it possible to manually increment a pointer to get the next element in memory? if so, how much should it be incremented by to get the next integer in a series of integers in memory?
 
Assuming you mean a series of integers to be an array of integers then the following example code might be of help.
Code:
var
  i: integer;
  ints: array [ 0.. 15 ] of integer;
  ip: ^integer;  // Pointer to an integer
begin
// Fill array with predictable numbers
  for i := Low(ints) to High(ints) do
    ints[i] := i + 100;

  ip := @ints;  // Point to first array element
  ShowMessage ( IntToStr ( ip^ ) );
  inc ( ip, sizeof(integer) );  // Point to next element
  ShowMessage ( IntToStr ( ip^ ) );
end;
Note that actual value to be incremented is best avoided by using the sizeof() function. This makes the code more robust (anticipating 64 bit integers?) and portable.


Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top