Print Friendly and PDF
C ++ Pointers conceptTo make it clear what is a pointer, it must figure out how the data in memory is stored, and how to read. If you define a variable in the program, give the variable at compile time to allocate memory. System based on variable type defined in the program, the allocation of space a certain length.

Concept of pointers

To make it clear what is a pointer, it must figure out how the data in memory is stored, and how to read. If you define a variable in the program, give the variable at compile time to allocate memory. System based on variable type defined in the program, the allocation of space a certain length.
For example, C ++ compiler system generally assigned 4-byte integer variable, allocate 4 bytes for the single-precision floating-point variables, assigning one byte character variable. Each byte memory area has a number, which Figure is the "address."

Figure 1


Be sure to find out the contents of a memory cell address memory unit difference between the two concepts. In the program access operation is typically performed by the variable name of the memory unit.In fact, the program has been compiled after the variable names to address variables, variable values ​​are accessed by the address. This address is accessed by way of variable value of the variable called direct access mode, or direct access.

You can also use an alternative called indirect access (indirect access) approach. Can define a special variable in the program, it is designed to store addresses. Figure 6.2 is a schematic of direct access and indirect access. In order to value 3 to the variable, there are two ways:

Number 3 to the unit directly to the integer variable i of the identified. Figure 2
The 3 to the unit pointer variable i_pointer points (which is identified by means of the variable i) in. Figure 2


figure 2

The so-called point, is to be embodied by the address. Because the address to find the desired variable unit, it can be said, pointing to the variable unit address. So will address visualize called "pointer", the address of a variable is called a pointer to the variable. If you have a variable is designed to store the address of another variable (i.e pointer), it is called a pointer variable. Value of the pointer variable (i.e the value stored in the pointer variable) is the address (i.e pointers).
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: