c ++ array initialization assignment

 1 #include<iostream>
 2 #include<string.h>
 3 #include<algorithm>
 4 #define max 0x3f
 5 using namespace std;
 6 int main()
 7 {
 8     int b[6];
 9     int a[5][5];
10     fill(a[0],a[0]+5*5,12);
11 //    memset(a,0,sizeof(a));
12 //    Memset (A, -1, the sizeof (A));
 13 is  //     Memset (A, max, the sizeof (A)); 
14      / * Fill initial value of the two-dimensional array, from a [0] beginning, rather than a * / 
15      / * and memset two-dimensional or one-dimensional array are assigned to only assign 0, -1, max (16 hex) * / 
16  //     memset (B, 0, the sizeof (B));
 . 17  //     Memset (B, -1, the sizeof (B));
 18 is  //     Memset (B, max, the sizeof (B)); 
. 19      Fill (B, B + . 6 , . 9 );
 20 is      COUT << " A array: \ n- " ;
 21 is      for ( int I = 0 ; I < . 5 ; I ++ )
22     {
23         for(int j=0;j<5;j++)
24         {
25             cout<<a[i][j]<<" ";
26         }
27         cout<<endl;
28     }
29     cout<<"b数组:\n";
30     for(int i:b)
31     {
32         cout<<i<<" ";
33     }
34     cout<<endl;
35      COUT << " The following is an array of c: \ n- " ;
 36      char c [ . 3 ] [ . 5 ];
 37 [      / * array of characters may be used memset, fill an arbitrary assignment. * / 
38 is      Memset (C, ' L ' , the sizeof (C)); / * Here is assigned to 'L' * / 
39      Fill (C [ 0 ] + . 7 , C [ 0 ] + . 8 , ' . 8 ' ); / * here the '8' to '1', you will find an array of like every c are the same.
40      strongly Tucao, '1' and 'l' In the console output not see the difference. * / 
41      / *Precisely, fill the assignment is starting at the specified location, and then subtracting the initial length position to the end position.
42      , this is c [0] + 8-c [0] + 7 = 1. So here only to c [0] +7 this one assignment. 
43 is      * / 
44 is      for ( int I = 0 ; I < . 3 ; I ++ )
 45      {
 46 is          for ( int J = 0 ; J < . 5 ; J ++ )
 47          {
 48              COUT << C [I] [J] << "  " ;
 49          }
 50          COUT << endl;
 51 is      }
 52 is }

Debugging can see how all the difference and the problem is it? The answer is a lot of output. The only way to see the contrast in order to know where to run to, and the expected difference in where, where the collapse.

Guess you like

Origin www.cnblogs.com/dayq/p/11949351.html