C89: On the array / pointer / reference

A. Array

1. integer array

(1) one-dimensional array
// one-dimensional array 
of static: int array [100]; 
static: int array [100] = { 1,2}; // initialization only two elements before 
static: int array [100] = { 0}; // All set to zero 
 
 
dynamic: int * Array = new new int [100]; 
     Delete [] Array; 
 
dynamic: int * Array = new new int [100] (1,2);     
     Delete [] Array;
 

 

(2) two-dimensional array
// array of two-dimensional 
static: int array [10] [10 ]; 
static: int array [10] [10 ] = {{1,1}, {2,2}}; 
 
Dynamic: int (* array) [n ] = new new int [m] [n-]; 
     Delete [] Array; 
 
dynamic: Array = new new int int ** * [m]; 
     for (I) 
        Array [I] = new new int [n-]; 
     for (I) 
        Delete [] Array [I]; 
     Delete [] Array; 
 
dynamic: Array = new new int int * [m] [n-]; 
    Delete [] Array;

 

(3) multi-dimensional arrays
int* array=new int[m][3][4];
delete[] array;

 

2. char array

char [] represents a character array

Note: The array name is a constant can not be modified, can not assign or change the name of the array

char a [10]; // a one-dimensional array of characters 
char a [10] [5] ; // a two-dimensional array of characters 
char a [5] = { ' a', 'b'}; // plurality of characters assigned to character array 
char a [] = { 'a ', 'b'}; // plurality of characters assigned to the character array 
 
char a [5] = { " abc"}; // string assigned to the character array 
char a [5 ] = "abc"; // string assigned to the character array 
char a [] = "abc" ; // string of characters assigned to the array 
 
// NOTE: string is always '\ 0' terminator as a string, the compiler has been automatically added at the end of the '\ 0'
 

 

3. The array parameter passing

(1) one-dimensional array of mass participation
// parameter passing one-dimensional array 
void FUNC (int * Array); 
 
void FUNC (int Array []);
 (2) two-dimensional array of mass participation
// two-dimensional array parameter passing 
void FUNC (int ** Array); 
 
void FUNC (int (* Array) [n-]);

 

II. Pointer

1.char*

char * The character pointer

* p = char "Test"; 
char * p = { "Test"}; 
 
// pointer because p is a string constant, it is recommended to write: const char * p = "test ";

 

3. Smart Pointers

4. The two-dimensional and three-dimensional pointer Pointer

 

III. Arrays and pointers

And the same 1.char * char [] of

When the transfer function parameters, and the character array can be replaced by another character pointers

the Test void (* int A) { 
 
    char * A = "ABC"; // calls the local function, a constant address pointer variable points will not disappear 
    char a [] = "abc" ; // the local function call, a memory arrays point will destroy 
} 
 
int main () { 
 
    int a [] = "Test";   
    int * P; 
    P = a & [0]; 
    P = a +. 1; 
 
    the Test (a); 
}

 

2.char * and char [] different

(1) The character pointer is a variable, the value may be changed, the character array name is a constant, not variable

(2) character pointer to a string constant, not variable, the name of a character array at the memory area may become

Guess you like

Origin www.cnblogs.com/k5bg/p/11121413.html