C语言(指针,数组)(附加)
2017-07-24 22:18
316 查看
#include<stdio.h>
void main()
{
//一维数组:
int buf[10]={1,2,3,4,5,6,7,8,9,10};
//下标法
printf("%d %d\n",buf[0],buf[9]);
//指针法:
printf("%d %d\n",*(buf+0),*(buf+9));
//指针变量:存储指针的变量
int* pbuf=buf;
printf("%d %d %d %d\n",*(pbuf+0),*(pbuf+4),pbuf[0],pbuf[4]);
//二维数组:
int score[4][5]={{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20}};
//引用:下标法,指针法
printf("%d\n",score[2][1]);
//行与列指针:
printf("%x %x %x %x\n",&score[0][0],&score[1][0],&score[2][0],&score[3][0]);
//行+n 指向第n行
printf("%x %x %x %x\n",score+0,score+1,score+2,score+3);
//列: 列+1指向下一列
printf("%x %x %x %x\n",*(score+0)+0,score[0]+1,score[0]+2,*(score+0)+3);
//打印元素:确定此元素的地址
printf("%d %d %d\n",score[2][2],(*(score+2))[2],*(*(score+2)+2));
//指针变量:
int* pscore=score;
printf("%d",*(pscore+1));//说明:pscore+1指向下个元素
//二维数组指针:
int (*mp)[5]=score;
printf("%x %x %x %x\n",mp,mp+1,mp+2,mp+3);
//行指针
printf("%x %x %x %x\n",*(mp+0)+0,mp[0]+1,*mp+2,mp[0]+3);
//第一行列指针
//第3行 通过mp指针
int i=0;
for(i=0;i<5;i++)
printf("%d %d\n",mp[2][i],*(*(mp+2)+i));
//第二列
for(i=0;i<4;i++)
printf("%d %d\n",mp[i][1],*(*(mp+i)+1));
for(i=0;i<20;i++)
{
// printf("%d ",mp[i/5][i%5]);
printf("%d %d\n",*(pscore+i),pscore[i]);
}
}
void main()
{
//一维数组:
int buf[10]={1,2,3,4,5,6,7,8,9,10};
//下标法
printf("%d %d\n",buf[0],buf[9]);
//指针法:
printf("%d %d\n",*(buf+0),*(buf+9));
//指针变量:存储指针的变量
int* pbuf=buf;
printf("%d %d %d %d\n",*(pbuf+0),*(pbuf+4),pbuf[0],pbuf[4]);
//二维数组:
int score[4][5]={{1,2,3,4,5},{6,7,8,9,10},{11,12,13,14,15},{16,17,18,19,20}};
//引用:下标法,指针法
printf("%d\n",score[2][1]);
//行与列指针:
printf("%x %x %x %x\n",&score[0][0],&score[1][0],&score[2][0],&score[3][0]);
//行+n 指向第n行
printf("%x %x %x %x\n",score+0,score+1,score+2,score+3);
//列: 列+1指向下一列
printf("%x %x %x %x\n",*(score+0)+0,score[0]+1,score[0]+2,*(score+0)+3);
//打印元素:确定此元素的地址
printf("%d %d %d\n",score[2][2],(*(score+2))[2],*(*(score+2)+2));
//指针变量:
int* pscore=score;
printf("%d",*(pscore+1));//说明:pscore+1指向下个元素
//二维数组指针:
int (*mp)[5]=score;
printf("%x %x %x %x\n",mp,mp+1,mp+2,mp+3);
//行指针
printf("%x %x %x %x\n",*(mp+0)+0,mp[0]+1,*mp+2,mp[0]+3);
//第一行列指针
//第3行 通过mp指针
int i=0;
for(i=0;i<5;i++)
printf("%d %d\n",mp[2][i],*(*(mp+2)+i));
//第二列
for(i=0;i<4;i++)
printf("%d %d\n",mp[i][1],*(*(mp+i)+1));
for(i=0;i<20;i++)
{
// printf("%d ",mp[i/5][i%5]);
printf("%d %d\n",*(pscore+i),pscore[i]);
}
}
相关文章推荐
- C语言 内存分配 地址 指针 数组 参数 实例解析
- 【C语言】n维数组的指针作为形参的方法
- C语言结构体里的成员数组和指针
- c语言字符指针数组经典,此后不必再担心字符串问题.
- C语言中的指针与数组
- iOS 学习第九天 C语言 指针与数组,结构体
- C语言学习笔记17——数组与指针
- C语言数组名与指针
- C语言指针数组和数组指针
- c语言----指针与数组(2)
- 【指针篇】C语言:指针与数组的区别,数组指针与指针数组的剖析。
- c语言数组与指针详解
- C语言 指针数组详解及示例代码
- C语言之指针和数组 1
- c语言数组的概念和指针的加减使用
- C语言数组与指针的区别
- C语言基础:C语言指针(5) - 指针和数组
- C语言中字符数组和字符串指针分析
- C语言中的指针和数组
- C语言数组参数与指针参数