二维数组的地址
#include <stdio.h>
void ModifyArray(int ArrayNew[3][4], int row, int colmun) ;
int main(int argc, char *argv[])
{
int array[3][4] ;
int i, j ;
for(i = 0; i < 3; i++)
{
for(j = 0; j < 4; j++)
{
array[i][j] = i*4 + j ;
}
}
for(i = 0; i < 3; i++)
{
for(j = 0; j < 4; j++)
{
printf("%d,", array[i][j]) ;
}
puts("\n") ;
}
ModifyArray(array, 3, 4) ;
for(i = 0; i < 3; i++)
{
for(j = 0; j < 4; j++)
{
printf("%d,", array[i][j]) ;
}
puts("\n") ;
}
return 0 ;
}
void ModifyArray(int ArrayNew[3][4], int row, int colmun)
{
int i, j;
int *p ;
//p = &ArrayNew[0][0] ;
//p = &ArrayNew[0] ;
p = &ArrayNew ;
for(i = 0; i < row; i++)
{
for(j = 0; j < colmun; j++)
{
*(p + i*4 + j) = i*4 + j + 12;
}
}
}
p = &ArrayNew ;
#include <iostream>
using namespace std;
int main()
{
int ArrayNew[2][3] = {
{1, 2},
{3, 4}
};
//p points to int
int *p = &ArrayNew[0][0];
cout<<"*p="<<*p<<endl;//*p = 1
p++;
cout<<"*p="<<*p<<endl;//*p = 2
p++;
cout<<"*p="<<*p<<endl;//*p = 0
p++;
cout<<"*p="<<*p<<endl;//*p = 3
int *p2 = (int *)&ArrayNew;
cout<<"*p2="<<*p2<<endl;
p2++;
cout<<"*p2="<<*p2<<endl;
int (*p3)[3]= ArrayNew;//ArrayNew equals ArrayNew[0]
cout<<"(*p3)[0]="<<(*p3)[0]<<endl;
cout<<"(*p3)[1]="<<(*p3)[1]<<endl;
cout<<"(*p3)[2]="<<(*p3)[2]<<endl;
p3++;//p3 -> ArrayNew[1]
cout<<"(*p3)[0]="<<(*p3)[0]<<endl;
cout<<"(*p3)[1]="<<(*p3)[1]<<endl;
cout<<"(*p3)[2]="<<(*p3)[2]<<endl;
int (*p4)[2][3] = &ArrayNew;//ArrayNew equals ArrayNew[0][0]
cout<<"(*p4)[0][0]="<<(*p4)[0][0]<<endl;
cout<<"(*p4)[1][0]="<<(*p4)[1][0]<<endl;
p4++;//p4 -> ArrayNew[2][3]'s next address
cout<<"(*p4)[0][0]="<<(*p4)[0][0]<<endl;//这个在使用中是很危险的,一定要注意!
return 0;
}
