Difference between revisions of "^"
From Lazarus wiki
Jump to navigationJump to search (add example) |
|||
Line 2: | Line 2: | ||
<div style="float:left; margin: 0 25px 20px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">^</div> | <div style="float:left; margin: 0 25px 20px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">^</div> | ||
+ | In [[ASCII]] the character code decimal<syntaxhighlight lang="pascal" enclose="none">94</syntaxhighlight> (or [[Hexadecimal|hexadecimal]] <syntaxhighlight lang="pascal" enclose="none">5E</syntaxhighlight>) is defined to be <syntaxhighlight lang="pascal" enclose="none">^</syntaxhighlight> (circumflex accent). | ||
+ | For any data type, a [[Pointer|pointer]] type for that data can be declared using the operator <syntaxhighlight lang="pascal" enclose="none">^</syntaxhighlight> in front of the data type. | ||
+ | <syntaxhighlight lang="pascal" line highlight="6-7,11,21-22"> | ||
+ | program pointerDemo(input, output, stderr); | ||
+ | type | ||
+ | listItem = record | ||
+ | data: integer; | ||
+ | // next _points_ _to_ a list item | ||
+ | next: ^listItem; | ||
+ | end; | ||
− | + | var | |
+ | start: ^listItem; | ||
− | + | begin | |
+ | new(start); | ||
+ | if not assigned(start) then | ||
+ | begin | ||
+ | writeLn(stderr, 'obtaining memory for start failed'); | ||
+ | halt(1); | ||
+ | end; | ||
+ | |||
+ | // _de-reference_ the pointer, follow it | ||
+ | start^.data := 7; | ||
+ | |||
+ | dispose(start); | ||
+ | end.</syntaxhighlight> | ||
+ | |||
+ | {{Symbols}} | ||
+ | |||
+ | [[Category:Code]] |
Revision as of 14:15, 24 March 2018
│
English (en) │
suomi (fi) │
русский (ru) │
^
In ASCII the character code decimal94
(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.
1program pointerDemo(input, output, stderr);
2
3type
4 listItem = record
5 data: integer;
6 // next _points_ _to_ a list item
7 next: ^listItem;
8 end;
9
10var
11 start: ^listItem;
12
13begin
14 new(start);
15 if not assigned(start) then
16 begin
17 writeLn(stderr, 'obtaining memory for start failed');
18 halt(1);
19 end;
20
21 // _de-reference_ the pointer, follow it
22 start^.data := 7;
23
24 dispose(start);
25end.
single characters |
|
character pairs |
|