^

From Lazarus wiki
Jump to: navigation, search

English (en) suomi (fi) русский (ru)

^

In ASCII the character code decimal 94 (or hexadecimal 5E) is defined to be ^ (circumflex accent).

For any data type, a pointer type for that data can be declared using the operator ^ in front of the data type.


  1. program pointerDemo(input, output, stderr);
  2.  
  3. type
  4. 	listItem = record
  5. 		payload: integer;
  6. 		// next _points_ _to_ a list item
  7. 		next: ^listItem;
  8. 	end;
  9.  
  10. var
  11. 	start: ^listItem;
  12.  
  13. begin
  14. 	new(start);
  15. 	if not assigned(start) then
  16. 	begin
  17. 		writeLn(stderr, 'obtaining memory for start failed');
  18. 		halt(1);
  19. 	end;

A pointer can be followed, dereferenced by appending a ^ to the identifier. Instead of having the memory address in your hands, you will look at the memory content at that address. If it is a typed pointer, operations and syntax for that type are valid, e.g. assignment in the following example.

  1. 	// _de-reference_ the pointer, i.e. follow it
  2. 	start^.payload := 7;
  3.  
  4. 	dispose(start);
  5. end.

However, attempting to follow a nil pointer will cause a runtime error (RTE 216 “general protection fault”). That is the situation the condition not assigned(start) in line 15 is supposed to catch.

see also


navigation bar: topic: Pascal symbols
single characters

+ (plus)  •  - (minus)  •  * (asterisk)  •  / (slash)
= (equal)  •  > (greater than)  •  < (less than)
. (period)  •  : (colon)  •  ; (semi colon)
^ (hat)  •  @ (at)  •  $ (dollar sign)  •  & (ampersand)

character pairs

<> (not equal)  •  := (becomes)  •  >< (symmetric difference)  •  // (double slash)