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 pointers and pointer variables in C++

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article will explain in detail how to use pointers and pointer variables in C++. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Let's first take a look at what are pointers and pointer variables?

1. The pointer refers to the address.

two。 Pointer variable, first of all, it is a variable, is a variable has an address, so the pointer variable has its own address. Second, the value stored in the pointer variable is an address, which can be the address of another variable or the address of the assigned heap.

From the output of the program, we can see that a, b, c are pointer variables, they all have their own address, and the address of each pointer variable is different. The address stored in these pointer variables is 0 when both a _ c is assigned to nullptr.

When the value of arecoery bpenc points to a different address, we will find that the address of the pointer variable arecine bpenc has not changed, but the address stored in the values of these pointer variables has changed. When we do * operations on these pointer variables, the value we get is the value of the variable stored in the stored address.

As can be seen from the above output, different pointer variables can point to the same address, and once the value stored in this storage address is changed, the * operation of the pointer variable pointing to that address will get the same changed value.

Judging from the above program output, the delete operation simply removes the value from the address where the value is stored, and does not point the pointer variable elsewhere.

If you want the corresponding pointer variable to point somewhere else, you need to add this part of the operation yourself, such as axinullptr. therefore, the address pointed to by the pointer variable a becomes 0, but the address pointed to by the pointer variable bmaine c has not changed.

So much for sharing about how to use pointers and pointer variables in C++. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.

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

Internet Technology

Wechat

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

12
Report