Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use pointer assignment in java

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use pointer assignment in java, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Pointer assignment is a data type in computer language. When using the structure pointer, we should first point the structure pointer to the structure. only after the pointer points to the structure can we use the pointer to refer to the member variables in the structure. you can assign values to the member variables in the structure and complete the corresponding operations.

Summary of pointer assignment operation

1. Add or subtract an integer from the pointer variable

Such as: p++p--p+ip-ip+=ip-=i, etc.

The actual meaning is as follows: pairi represents the address calculation: paircedicine c is the number of bytes, integer center2,

Real type cymbals 4, character type cymes 1.

It is worth noting that the pointer + (or Pmuri -) indicates that the direction of the pointer has changed, while the pointer (or Pmuri) indicates that the direction of the pointer has not changed.

2. Pointer variable assignment

For example, p=&aa is a variable and p is a pointer variable

P=arrayarray is the array name

P=&array

P=maxmax is the function name

P1=p2p2 is a pointer variable

Note: you cannot assign an integer or constant to p, such as pause 1000, nor can you assign p to an integer variable, such as iProjecp.

3. Pointer variables can be assigned null values

For example: pendant null; the actual NULL is the integer 0.

4. Two pointer variables can be subtracted as two pointer variables point to elements of the same array (right)

Then p2-p1=4-1 is 3, but p1+p2 is meaningless.

5. Comparison of two pointer variables

If two pointers point to elements of the same array, you can compare

Such as: p1p2

Null type pointer

The new ANSI standard adds a null type pointer, which is defined in general form:

Void* variable name

Type conversion should be done when it is used, such as:

Void*p; (int*) p

How to use pointer assignment

1. When using a pointer, it must be initialized. If there is no directly indicated object, you can point the pointer variable to NULL.

For example: int*p=NULL

2. After the pointer has been used, the inner space pointed to by the pointer has been released, then the pointer should point to NULL, otherwise there will be a free state, such a pointer has a certain threat to the whole program

For example:

Int*p=NULL

P = (int*) malloc (sizeof (int))

If (NULL==p)

{

Return-1

}

After the requested memory is used up and freed, you need to point the pointer to NULL;, that is, p=NULL.

The above is all the content of the article "how to use pointer assignment in java". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report