⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ptrmulti.c

📁 里面包含很多c语言的源码
💻 C
字号:
/* Demonstrates passing a pointer to a multidimensional */
/* array to a function. */

#include <stdio.h>

void printarray_1(int (*ptr)[4]);
void printarray_2(int (*ptr)[4], int n);

int main( void )
{
   int  multi[3][4] = { { 1, 2, 3, 4 },
                      { 5, 6, 7, 8 },
                      { 9, 10, 11, 12 } };

   /* ptr is a pointer to an array of 4 ints. */

   int (*ptr)[4], count;

   /* Set ptr to point to the first element of multi. */

   ptr = multi;

   /* With each loop, ptr is incremented to point to the next */
   /* element (that is, the next 4-element integer array) of multi. */

   for (count = 0; count < 3; count++)
       printarray_1(ptr++);

   puts("\n\nPress Enter...");
   getchar();
   printarray_2(multi, 3);
   printf("\n");
   return 0;
}

void printarray_1(int (*ptr)[4])
{
/* Prints the elements of a single four-element integer array. */
/* p is a pointer to type int. You must use a type cast */
/* to make p equal to the address in ptr. */

     int *p, count;
     p = (int *)ptr;

     for (count = 0; count < 4; count++)
         printf("\n%d", *p++);
}

void printarray_2(int (*ptr)[4], int n)
{
/* Prints the elements of an n by four-element integer array. */

     int *p, count;
     p = (int *)ptr;

     for (count = 0; count < (4 * n); count++)
         printf("\n%d", *p++);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -