#include <stdio.h>
#define FUNCTION_START() printf("-----------%s(%d)--start----------\n",__FUNCTION__, __LINE__)
#define FUNCTION_END() printf("-----------%s(%d)--end------------\n",__FUNCTION__, __LINE__)
int pointToPoint(int **point, int row, int col){
FUNCTION_START();
int i = 0;
int j = 0;
printf("point[0]=%p,point[1]=%p,point[2]=%p\n",point[0],point[1],point[2]);
for(i = 0; i < row; i ++){
for(j = 0; j < col; j ++){
printf("&point[%d][%d] = %p\n",i,j,&point[i][j]);
printf("point[%d][%d] = %d\n",i, j, point[i][j]);
}
}
FUNCTION_END();
}
int pointToArray(int *point[3], int row, int col){
FUNCTION_START();
int i = 0;
int j = 0;
printf("point[0]=%p,point[1]=%p,point[2]=%p\n",point[0],point[1],point[2]);
for(i = 0; i < row; i ++){
for(j = 0; j < col; j ++){
printf("&point[%d][%d] = %p\n",i,j,&point[i][j]);
printf("point[%d][%d] = %d\n",i, j, point[i][j]);
}
}
FUNCTION_END();
}
int arrayToPoint(int (*point)[3], int row, int col){
FUNCTION_START();
int i = 0;
int j = 0;
printf("point[0]=%p,point[1]=%p,point[2]=%p\n",point[0],point[1],point[2]);
for(i = 0; i < row; i ++){
for(j = 0; j < col; j ++){
printf("&point[%d][%d] = %p\n",i,j,&point[i][j]);
printf("point[%d][%d] = %d\n",i, j, point[i][j]);
}
}
FUNCTION_END();
}
void main(){
int **point_to_point;
int (*array_to_point)[3];
int *point_to_array[3];
int *point;
int i = 0;
int j = 0;
int array[3][3] = {{1,2,3},{4,5,6},{7,8,9}};
point = (int *)array;
for(i = 0; i < 9; i ++){
printf("point[%d] = %d\n", i, point[i]);
}
point_to_point = (int **)array;
printf("sizeof(point_to_point)=%d,point_to_point=%p,array=%p,(point_to_point+1)=%p,*point_to_point=%p,*(array)=%p,*(point_to_point+1)=%p\n",
sizeof(point_to_point),point_to_point,array,(point_to_point+1),*point_to_point,*array,*(point_to_point+1));
array_to_point = array;
arrayToPoint(array_to_point, 3, 3);
arrayToPoint(array, 3, 3);
for(i = 0; i < 3; i ++){
point_to_array[i] = array[i];
}
point_to_point = point_to_array;
pointToArray(point_to_array, 3, 3);
pointToPoint(point_to_point, 3, 3);
pointToArray(point_to_point, 3, 3);
pointToPoint(point_to_array, 3, 3);
}