Wu Yuxiong - born natural C ++ language study notes: C ++ pointer

Each variable has a memory location, each memory location addresses are defined using a hyphen (&) operator access, it represents an address in memory.
#include <the iostream> the using namespace STD; int main () 
{ int   var1;
    char var2 [ 10 ]; 
   COUT << " var1 variable address: " ; 
   COUT << & var1 << endl; 
   COUT << " address variable var2 : " ; 
   COUT << var2 & << endl; return 0 ; 
} 
when the above code is compiled and executed, it produces the following results: 
address variables var1: 0xbfebd5c0 
address var2 variables: 0xbfebd5b6
 
 
 

   
 
 
 
    
When the above code is compiled and executed, it produces the following results: 
address variables var1: 0xbfebd5c0 
address var2 variables: 0xbfebd5b6
Pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like before, like other variables or constants, you must use other variables to store address pointers, be declared. The general form of the pointer variable declaration is: 
type * var - name; 
Here, type is the base type pointer, it must be a valid C ++ data types, var -name name pointer variable. Used to declare a pointer asterisk * asterisk used in multiplication are the same. However, in this statement, the asterisk is used to specify a variable is a pointer. The following statement is valid pointer:
 int     * IP;     / * a pointer integer * / 
double * DP;     / * a type double pointer * / 
a float   * FP;     / * a pointer to float * / 
char    * CH ;     / * pointer to a char type * / 
long-pointers all the actual data type of the value, either integer, float, string, or other data types are the same, are representative of a memory address hexadecimal number. The only difference between the different types of data pointers, the pointer points to a different constant or variable data type.
Frequently performed using the following pointers: Define a pointer variable, the variable is assigned to the address pointer, the value of the available address in the access pointer variable. These by using unary * operand Returns the value of the variable of the specified address. 
#include <the iostream> the using namespace STD; int main () 
{ int var = 20 is ;    // declare real variables int   * IP;         // declare a pointer variable  
   IP = & var ;        // address stored in the pointer variable var  
   COUT << " the Value of variable var: " ; 
   COUT << var << endl; // output address stored in the pointer variable 
   cout <<
 
 
 

     
   


 
   " The Address IP variable Stored in: " ; 
   COUT << IP << endl; 
 
   // access the address pointer value 
   COUT << " the Value of variable * IP: " ; 
   COUT << IP * << endl; 
 
   return  0 ; 
} 
when the above code is compiled and executed, it produces the following results: 
the Value of var variable: 20 is 
the Address Stored in IP variable: 0xbfc601ac 
the Value of * IP variable: 20 is
C ++ pointer Detailed 
C ++ Null pointer C ++ support a null pointer. A NULL pointer is defined in the standard library zero constant. 
C ++ pointer arithmetic four-arithmetic operation can be performed on pointers: ++, -, +, - 
C ++ has a close relationship between pointers vs array pointers and arrays. 
C ++ pointer arrays can be used to define the array stores pointers. 
C ++ pointer to a C ++ pointer allows a pointer to a pointer. 
C ++ parameter passing parameters to a function pointer passed by reference or address, so that transmission is changed in the calling function. 
C ++ function returns a pointer to the C ++ allows the function returns a pointer to the local variables, static variables and dynamic memory allocation.

 

Guess you like

Origin www.cnblogs.com/tszr/p/12148681.html