Pointer type in Delphi

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.