如何取二维数组指针的第一列,第一行我知道是*p=a

如题所述

假如有一个二维数组a[ i][ j]和一个指针*p;
一。如果用列指针定义,即p=*a或p=a[ 0],要取第一列,用一个循环for(;p<=p+j;p++) , 取值即*p;
二。如果用行指针定义,即(*p)(j),若这样定义,取第一列元素时,用一个for循环,即
for(m=0;m<j;m++),然后用*(*(p+i)+m)进行取值 即可
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-12-25
#include<stdio.h>

int max(int* mat, int row, int col)
{
int i,j;
int max;

max=*mat;

for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(max<*(mat+i*col+j))
{
max=*(mat+i*col+j);
}
}
}
return max;
}

void input(int* mat, int row, int col)
{
int i,j;

for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
scanf("%d", mat+i*col+j);
}
}
printf("\n");
}

int main(void)
{
int m;
int mat[2][5];

printf("请输入 %d 个整数:\n", 2*5);
input(&mat[0][0], 2, 5);
m=max(&mat[0][0], 2, 5);
printf("max= %d\n", m);

return 0;
}
相似回答