First, let's talk about how pointer types are defined in Delphi:
Definition Syntax of pointer type
Type
<Pointer type identifier >=^ <base type>;
The type of the pointer pointing to a dynamic variable is identified by the base type after the ^ character, and the ^ symbol is the pointer type. In C ++, the * symbol is used to represent the pointer type.
Example
Type
Student = record // defines the record type, which is similar to the structure type in C ++.
Name: String [8];
Number: integer;
Sex: (B, G );
Age: integer;
End;
Per = ^ student; // per is a record type pointer Structure
VaR
P1, p2: Per; // P1, P2 is pointer type, and P1, P2 is a dynamic variable of record type
R: ^ char; // The R pointer variable is a dynamic variable pointing to the character type.
What does a pointer-type operation look like? Let's give a simple example.
Type
STR = string [255]; // you can specify a string of 255 characters.
PTR = ^ STR; // define the pointer type
VaR
S: STR; // s indicates static memory allocation.
P: PTR; // P indicates the dynamically allocated memory.
S: = 'hello ';
P ^: = 'hello'; // The ^ symbol indicates the access to the pointer variable. Of course we can also use this
S: = P ^; this is equivalent to the above line
Do you know you will?
What does P and P ^ mean?
P is a 4-byte pointer variable and is statically stored. It is the first address of the dynamic variable memory.
P ^ is a 256-byte string variable and is dynamically stored. The data it points to can be changed at will.
Let's write so much today. I hope you will continue to pay attention to my weibo posts. please correct me if there are any errors ~
Pointer type in Delphi