Relationship between the pointer and the pointer memory address

. 1  #pragma Region ++ pointer, the address pointer is stored within m bits is increased, the size of the number m of bytes occupied by the stored content is determined according to
 2  
. 3  // here to illustrate this relationship by a sequence table 
. 4  the using  namespace STD;
 . 5 typedef int the Status;
 . 6 typedef int elemType;
 . 7 constexpr Auto the MAXSIZE = 100 ; // maximum length; 
. 8 typedef struct SqList {
 . 9      elemType * elem; // base address 
10      int length; // actual length 
. 11  } SqList;
 12 is  
13 isInitLsit_Sq the Status (SqList & L) { // Constructs an empty sequence table; represents & way transmission, the argument passed to the parameter values, unity thunk 
14      L.elem = new new elemType [the MAXSIZE]; // to sequentially space allocation table; MAXSIZE apply a new new type of spatial ElemType 
15      IF Exit (the OVERFLOW) (L.elem!); // storage allocation failed 
16      L.length = 0 ; // empty list of length 0 
. 17      return  . 1 ;
 18 is  }
 . 19  
20 is the Status ListInsert_Sq (SqList L &, int I, elemType E) { // return value 
21 is      IF (I < . 1 || I> + L.length . 1 ) return 0 ; // determines whether the insertion position legitimate 
22 is      IF (== L.length the MAXSIZE) return  0 ; // determine whether the memory is full 
23 is      for ( int J = L.length; J> = I - . 1 ; J, ) { // n-i to the rearward movement of the element 
24          L.elem [J + . 1 ] = L.elem [J];
 25      }
 26 is      L.elem [i - . 1 ] = E; // E placing the i-th position 
27      ++ L.length; // table length + 1'd 
28      return  0 ;
 29  }
 30  
31 is  //E acquisition element content according to the position of the element I 
32  int LocateElem (SqList L, elemType e) {
 33 is      // lookup table does not affect the linearity length and content, the content of the argument value has been given by the user 
34 is      for ( int I = 0 ; I < L.length; I ++ )
 35          iF (L.elem [I] == E) return I + . 1 ;
 36      return  0 ; // if they execute return 0 for statement is false false iF expression || 
37  }
 38 is  #pragma endregion
 39  
40  int main ()
 41 is  {
 42 is      SqList B; // B for creating the name of sequence table 
43     InitLsit_Sq (B);
 44 is      // value of the order of Table B were 2,3,4 
45      ListInsert_Sq (B, . 1 , 2 );
 46 is      ListInsert_Sq (B, 2 , . 3 );
 47      ListInsert_Sq (B, . 3 , . 4 );
 48      int * P1 = & (B.elem [ 0 ]);
 49      int * P2 = & (B.elem [ . 1 ]);
 50      int * & P3 = (B.elem [ 2 ]);
 51 is      int * P4 = ++ p1; // first assigned to p4, then ++ for p1 
52      printf ( "%0x, %0x, %d, %d\n", p1, &(B.elem[0]), *p1, (B.elem[0]));
53     printf("%0x, %0x, %d, %d\n", p2, &(B.elem[1]), *p2, (B.elem[1]));
54     printf("%0x, %0x, %d, %d\n", p3, &(B.elem[2]), *p3, (B.elem[2]));
55     printf("%0x, %0x, %d, %d\n", p4, &(B.elem[0]), *p4, (B.elem[0]));
56 }

 

Guess you like

Origin www.cnblogs.com/Ecogolle/p/11009451.html