Pointer array and array pointer

Source: Internet
Author: User
// Understanding the array pointer and pointer array should begin with the definition, and the understanding of the Priority
// For an array of pointers, such as int * P [4. Because the array is defined first
// For an array pointer, such as int (* P) [4], the pointer is defined first.

# Include <iostream> # include <sys/time. h> using namespace STD; int main () {int arr [4] [4] = {1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; int * P [4]; // pointer array. [] the priority is higher *. P is an array containing four pointers to integer data, INT (* q) [4]; // array pointer, () with a high priority, indicating that Q is a pointer, this Pointer Points to the first address of an array of four elements for (INT I = 0; I <4; I ++) {for (Int J = 0; j <4; j ++) printf ("% 4D", arr [I] [J]); printf ("\ n ");} printf ("\ n"); q = arr; For (INT I = 0; I <4; I ++) {for (Int J = 0; j <4; j ++) {printf ("% 4D", * (q + I) + J); // is equivalent to a second-level pointer for an array pointer? } Printf ("\ n");} printf ("\ n"); For (INT I = 0; I <4; I ++) P [I] = arr [I]; // array of pointers, so that each element in the array corresponds to the address at the beginning of each row of the For (INT I = 0; I <4; I ++) {for (Int J = 0; j <4; j ++) printf ("% 4D", * (p [I] + j )); printf ("\ n");} printf ("\ n ");}

 

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.