Pointer array/array pointer

Source: Internet
Author: User

#include <iostream>using namespacestd;//Note how pointer arrays and array pointers point to two-dimensional arrays, respectively.#include <stdio.h>Main () {Static intm[3][4]={0,1,2,3,4,5,6,7,8,9,Ten, One};/*define two-dimensional array m and initialize*/     int(*p) [4];//The array pointer p is a pointer to a one-dimensional array with 4 int elements per one-dimensional array    inti,j; int*q[3];//pointer array q is an array, array elements are pointers, 3 int pointersP=m;//P is a pointer that can point directly to a two-dimensional arrayprintf"--array pointer output element--\n");  for(i=0;i<3; i++)/*outputs the values of each element in a two-dimensional array*/    {         for(j=0;j<4; j + +) {printf ("%3d", * (p[i]+j)); //printf ("%3d", * (* (p+i) +j));} printf ("\ n"); } printf ("\ n");  for(i=0;i<3; i++,p++)//p can be seen as a row pointer{printf ("%3d", **p);//the first element of each rowprintf"%3d", * (*p+1));//the second element of each rowprintf"%3d", * (*p+2));//the third element of each rowprintf"%3d", * (*p+3));//the fourth element of each rowprintf"\ n"); } printf ("\ n"); printf ("--pointer array output element--\n");  for(i=0;i<3; i++) Q[i]=m[i];//Q is an array, element Q[i] is a pointer     for(i=0;i<3; i++)    {         for(j=0;j<4; j + +) {printf ("%3d", Q[i][j]);//Q[i][j] can be replaced by * (Q[I]+J)} printf ("\ n"); } printf ("\ n"); printf (""); q[0]=m[0];  for(i=0;i<3; i++)    {         for(j=0;j<4; j + +) {printf ("%3d", * (q[0]+j+4*i)); } printf ("\ n"); } printf ("\ n"); }

Output Result:

This code is very well written .....

Pointer array/array pointer

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.