Two pointer input characteristics

. 1  #if . 1
  2  #define _CRT_SECURE_NO_WARNINGS
  . 3 #include <stdio.h>
  . 4 #include <stdlib.h>
  . 5 #include < String .h>
  . 6 #include <limits.h>
  . 7 #include <ctype.h>
  . 8 # the include <math.h>
  . 9  // input characteristics: the calling function to allocate memory, the called function is used 
10  void printArray ( int ** Array, int len) {
 . 11      for ( int I = 0 ; I <len; I ++ ) {
 12 is          the printf ( " % D \ n- ", * Array [I]);
 13 is      }
 14 }
 15 Test01 () {
 16      // allocate memory in the heap 
. 17      int * Array = the malloc ( the sizeof ( int ) * . 5 );
 18 is      // create five elements on the stack 
. 19      int A1 = 10 ;
 20 is      int A2 = 20 is ;
 21 is      int A3 = 30 ;
 22 is      int A4 = 40 ;
 23 is      int A5 = 50 ;
 24  
25     array[0] = &a1;
26     array[1] = &a2;
27     array[2] = &a3;
28     array[3] = &a4;
29     array[4] = &a5;
30     //打印数组
31     printArray(array, 5);
32 
33     if (array != NULL) {
34         free(array);
35         array = NULL;
36 
37     }
38 }
39 // allocate memory on the stack 
40  void Test02 () {
 41 is      int * Array [ . 5 ];
 42 is      for ( int I = 0 ; I < . 5 ; I ++ ) {
 43 is          Array [I] = the malloc ( the sizeof ( int ));
 44 is          * (array [I]) = 100 + I;
 45      }
 46 is      // print array 
47      int len = the sizeof (array) / the sizeof ( int *); //Here is to be noted that the calculation of an array element or coordinates 
48      printArray (Array, len);
 49      
50      for ( int I = 0 ; I <len; I ++ ) {
 51 is          IF (! Array [I] = NULL) {
 52 is              Free (Array [I]);
 53 is              Array [I] = NULL;
 54 is          }
 55      }
 56 is }
 57 is  int main ( int argc, char * the argv [])
 58 {
 59  
60      Test01 ();
 61 is      System ( " PAUSE");
62 
63     return 0;
64 }
65 #endif
 

19:57

Guess you like

Origin www.cnblogs.com/MyLoveLiJuan/p/11852374.html