#include<iostream.h>
void f(int *t,int n)
{
int *k;
for(k=*(t+n);k<=*(t+n)+2;k++)//错误显示:can not convert int to int *
cout<<*k;
}
void main()
{
int a[3][3]={{1,2,3},
{4,5,6},
{7,8,9}};
int *p=*(a+0);
f(p,1);//打印第1行
}
...全文
1107打赏收藏
搞不懂的二维数组指针(打印数组的某一行)
#include void f(int *t,int n) { int *k; for(k=*(t+n);k<=*(t+n)+2;k++)//错误显示:can not convert int to int * cout<<*k; } void main() { int a[3][3]={{1,2,3}, {4,5,6}, {7,8,9}}; int *p=*(a+0); f(p,1);//打印第1行 }
#include<iostream.h>
void f(int *t,int n)
{
int *k;
for(;k<=2;k++)//错误显示:can not convert int to int *
cout<<*k;
}
void main()
{
int a[3][3]={{1,2,3},
{4,5,6},
{7,8,9}};
int *p=*(a+0);
f(p,1);
}
你定义的 K是int 指针。
而 *(t+n)等价于t[n],它是int值。
所以出现错误。
for(k=*(t+n);k<=*(t+n)+2;k++)//错误显示:can not convert int to int *
cout<<*k;
改为
for(k=t+(n-1)*3;k<t+n*3;k++)
cout<<*k;
这里的3是每行的列数