Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-03 10:23:49 11月08日 Update

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.

Tags: Array pointer element object address point variable type byte space size that is output memory special two-dimensional local character offset integer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Redmi Apple MySQL MariaDB