您的位置:首页 > 其它

指针学习,遍历数组的值和每个值的地址

2015-04-19 00:00 260 查看
#include <stdio.h>
main()
{
int a[5] = {2,8,7,0,6};
int *p;
p = a;

printf("the first value is: %d\n",*p);
printf("the second value is: %d\n",*(p+1));
printf("the third value is: %d\n",*(p+2));
printf("the forth value is: %d\n",*(p+3));
printf("the fifth value is: %d\n",*(p+4));

printf("\nthe first addr is: %p\n",p);
printf("the second addr is: %p\n",p+1);
printf("the third addr is: %p\n",p+2);
printf("the forth addr is: %p\n",p+3);
printf("the fifth value is: %p\n\n",p+4);

int i;
for (i = 0; i <= 4; i++)
printf("a[%d] value is %d, address is: %p\n",i,*(p+i),(p+i));
p += 1;

return;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐