当前位置:编程学习 > C/C++ >>

数组指针

 #include<stdio.h>
 
int main()
{
        int array[3][4]={{11,12,13,14},{21,22,23,24},{31,32,33,34}};
        int i,j,*pointer;
        for(i=0;i<3;i++)
        {
        for(j=0;j<4;j++)
                printf("%d  ",array[i][j]);
        printf("\n");
        }
 
        printf("array=%d\n",array);
        printf("Address of array[0][1]=%d\n",&array[0][1]);
        printf("array[0]=%d\n",array[0]);
        printf("array+1=%d\n",array+1);
        printf("*(array+1)=%d\n",*(array+1));
        printf("*(*(array+1))=%d\n",*(*(array+1)));
        printf("*(*(array+1)+1)=%d\n",*(*(array+1)+1));
 
 
}
 
 
 
结果是:
 
11  12  13  14
21  22  23  24
31  32  33  34
array=-1080173016
Address of array[0][1]=-1080173012
array[0]=-1080173016
array+1=-1080173000
*(array+1)=-1080173000
*(*(array+1))=21
*(*(array+1)+1)=22
 
 
行指针:array + i   ----指向第i行数组
        array[i]    ----指向第i行数组
 
列指针:*(array + i) + j -----指向第 i 行 j 列
         array[i]+j
 
数值:*((*array+i)+j)
       *(array[i]+j)     == array[i][j]
作者“cafe”

补充:软件开发 , C语言 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,