Basis of Algorithm and Data Structure Pointers and arrays

Pointers and arrays:

  Pointer and one-dimensional array:

     Array name:

       Name is a one-dimensional array pointer constant whose value can not be changed it is stored in a one-dimensional array element address of the first one-dimensional array of points to the name of the array index 0 as the first element.

 

Index and pointer of the relationship:

. 1 A [I] == >> << * (A + I) >> << == * (I + A) >> << == I [A] is equivalent to the notation //
. 1 #include <stdio.h>
 2  int Mian () {
 . 3      int A [ . 5 ];
 . 4      the printf ( " % P,% P " , A, A + . 1 ); // % output P stored in hexadecimal the first two array element address, addresses are sequential 
. 5      return  0 ;
 . 6 }

(One byte is an address, int type four-byte, double eight bytes, char a byte pointer variable only all 4 bytes, the entire variable represents the address with the first address byte )

 

How to modify the contents of the calling function in a one-dimensional array by the called function:

  Two parameters:

     1. Store the first element of the array pointer variable

        2. The length of the array of integer variable storage

 1 #include<stdio.h>
 2 void arry(int* p,int len){
 3     int i;
 4     for(i = 0;i<len;i++){
 5         printf("%d\n",p[i]);
 6     }
 7 }
 8 int main(){
 9     int a[5]={1,2,3,4,5};
10     arry(a,5);//Transmitting array name, do not forget the length of the array 
. 11      return  0 ;
 12 is }

 

Guess you like

Origin www.cnblogs.com/sunbr/p/11247344.html