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

What are the pointers in the C++ array and array names

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

Share

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

This article shows you what the pointers in C++ arrays and array names are like, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

I. pointer 1.1 the difference between pointer variables and ordinary variables

Pointer: the essence of a pointer is a variable, which is not fundamentally different from an ordinary variable. The complete pointer should be called pointer variable, or pointer for short. It means to point. The pointer itself is an object, and the pointer does not need to be assigned at the time of definition.

1.2 Why do you need pointers

Pointers appear for indirect access. There is indirect access in the assembly, which is actually indirect in the addressing mode of CPU.

Indirect access (indirect addressing of CPU) is determined by CPU design time, which determines that assembly language must be able to implement question-and-answer search and that C language on top of assembly must also implement profile addressing.

1.3 pointer use trilogy

Trilogy: defining pointer variables, associating pointer variables, dereferencing

(1) when we int * p define a pointer variable p, because p is a local variable, it also follows the general law of the local variable in C language (if the local variable is defined and not initialized, the value is random), so what is stored in the p variable is a random number.

(2) if we dereference p at this time, it is equivalent to accessing the memory space with the address of this random number. I don't know whether this space can be accessed or not (maybe not), so if you directly define a pointer variable without a valid address, dereferencing will definitely die.

(3) define a pointer variable to de-reference without binding a valid address, just like taking a boring gun and turning it around a few times and then firing it.

(4) the meaning of pointer binding is to make the pointer point to a place that is accessible and should be accessed (just like the process of aiming and targeting with a gun). The dereference of the pointer is to access the target variable indirectly (as if shooting is to hit the target)

Int val = 43 nint * p = & val; / / & the right value is the character cout.

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