The application of two-dimensional array

Source: Internet
Author: User

Two-dimensional arrays: two-dimensional arrays can be thought of as row-based, one-dimensional arrays.

Example: a[3][3]={{1,2,3},{4,5,6}.{ 7,8,9}} can be seen as being that the array is made up of three elements, each of which includes a one-dimensional array of three numbers.

  1. Initialization of two-dimensional arrays

#include <stdio.h>

int main ()

{int p[3][3]={{1,2,3},{4,5,6},{7,8,9}};

int i=0,j=0;

for (i=0;i<3;i++)

{for (j=0;j<3;j++)

{printf ("%d", p[i][j]);

}

printf ("\ n");

}

return 0;}

2. Two-dimensional arrays as function parameters: two-dimensional arrays as function parameters, pass the address, the array of the two-dimensional array is an argument, representing the first element (including three data) of the first address.

#include <stdio.h>

void My_find (int (*p) [3])

{int i=0,j=0;

for (i=0;i<3;i++)

{for (j=0;j<3;j++)

{printf ("%d", p[i][j]);

}

printf ("\ n");

}

}

int main ()

{int p[3][3]={{1,2,3},{4,5,6},{7,8,9}};

My_find (P);

return 0;

}


This article is from the "local and static Variables" blog, reproduced please contact the author!

The application of two-dimensional array

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.