C语言求助P26
把小甲鱼老师二维数组的例子#include <stdio.h>
int main()
{
int array = {
{0, 1, 2, 3},
{4, 5, 6, 7},
{8, 9, 10, 11}};
int (*p);
int i, j;
p = array;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 4; j++)
{
printf("%2d ", *(*(p+i)+j));
}
printf("\n");
}
return 0;
}
改为
#include<stdio.h>
int main()
{
int a = {
{1,2,3,4},
{5,6,7,8},
{9,10,11,12}};
int *p = a;
int i;
for (i = 0;i < 12;i++)
{
printf("%2d\n",*(p + i));
}
return 0;
}
也可以执行成功
但出现了initialization of ‘int *’ from incompatible pointer type ‘int (*)’ [-Wincompatible-pointer-types]
why? 这里有一篇相似的文章
https://blog.csdn.net/m0_37357063/article/details/106048297
应该能找到答案 肖-肖 发表于 2021-5-21 22:16
这里有一篇相似的文章
https://blog.csdn.net/m0_37357063/article/details/106048297
应该能找到答案
变成这样了initialization of ‘int *’ from incompatible pointer type ‘int (*)’ [-Wincompatible-pointer-types]
本质上是一样的 连续的内存空间
页:
[1]