#include <stdio.h> #include <stdlib.h> int main(){ int a = 100; void *p = &a; printf("a:%d address:%p\n",*(int*)p, &a); //unsigned int *pt = (unsigned int*)0xbfa70ee8; int *pt = (int*)malloc(sizeof(int)); *pt = 200; printf("ptv:%p v:%d\n",pt,*pt); printf("********************行指针遍历二维数组*************************\n"); //二维数组的指针地址 int fa[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}; //行指针指针遍历输出二维数组 int i,j; for(i=0;i<3;i++) { for(j=0;j<4;j++){ printf("fa[%d][%d]=%d %p\n",i,j, *(*(fa+i)+j),*(fa+i)+j); } } printf("******************用数组名 列指针遍历二维数组***************************\n"); //定义指针 int *col = fa[0];//col是某行某列的指针 把第一行地址赋值给指针col for(;col<fa[0]+12; col++){ //地址每次循环+1指向下一行一列 if( (col-fa[0])%4==0 ){ printf("\n"); } printf("%d ", *col); } printf("******************用指针 列指针遍历二维数组***************************\n"); int *pp = *fa; int *arr = *fa;//二维数组首地址等同于 int *arr = fa[0] for(;arr<pp+12; arr++){ //地址每次循环+1指向下一行一列 if( (arr-pp)%4 == 0 ){ printf("\n"); } printf("%d ", *arr); } return 0; }