C pointer programming path-fourth note

Source: Internet
Author: User

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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.