C pointer programming path-fourth note
// Multiple pointer learning methods for Arrays
// Define two-digit Array
// Int date [4] [5];
// Indicates that all the members of this array are of the int type.
// Int date [4] [5] = {
// {1, 2, 3, 4, 5 },
// {1, 2, 3, 4, 5 },
// {1, 2, 3, 4, 5 },
// {1, 2, 3, 4, 5}
//};
// Or int date [4] [5] = };
// Access the two-digit array in the example
# Include
# Include
Using namespace std;
Int main ()
{
Int date [4] [5] = {
{1, 2, 3, 4, 5 },
{1, 2, 3, 4, 5 },
{1, 2, 3, 4, 5 },
{1, 2, 3, 4, 5 },
};
Printf ("date [4] [5]: \ n ");
For (int I = 0; I <4; ++ I)
{
For (int j = 0; j <5; ++ j)
{
Printf ("% d", date [I] [j]);
}
Printf ("\ n ");
}
Return 0;
}
// Pointer and two-dimensional array
// Use a pointer to check the memory address of each element?
// Point the pointer to the beginning of each memory unit in an emergency
// For example, & date [I] [j] indicates the address of each element.
# Include
# Include
Using namespace std;
Int main ()
{
Int date [4] [5] = {1, 2, 3, 4, 5 }};
Printf ("the address of each element is :");
For (int I = 0; I <4; ++ I)
{
For (int j = 0; j <5; ++ j)
{
Printf ("% p \ t", & date [I] [j]);
}
Printf ("\ n ");
}
Return 0;
}
// Pointer
//
// Int ** date;
// Pointer to the pointer variable;
# Include
# Include
Using namespace std;
Int main ()
{
Char * name [] = {"China", "BeiJing", "LongMai "};
Char ** p_name;
Printf ("name [0]: % p \ n", name [0]);
Printf ("name [1]: % p \ n", name [1]);
Printf ("name [2]: % p \ n", name [2]);
Printf ("\ n ");
P_name = & name [0];
Printf ("& name [0]: % p \ n", p_name );
P_name = & name [1];
Printf ("& name [1]: % p \ n", p_name );
P_name = & name [2];
Printf ("& name [2]: % p \ n", p_name );
Printf ("\ n ");
Return 0;
}