2. 使用指针操作数组

来源:互联网 发布:网络作家秦简的照片 编辑:程序博客网 时间:2024/05/06 23:48

2. 使用指针操作数组

2.1 可以使用数组名作为数组第一个元素的指针。
2.2 实例
#include <stdio.h>
void test_pointer1(){
            int a[] = {1,2,3,4};
            // a 表示数组第一个元素的地址
            printf("a=%p\n",a);
            int *p = &a[0];
            printf("p=%p\n",p);
}
// 使用指针操作数组
void test_pointer2(){
            int a[] = {1,2,3,4,5};
            int *p = a;
            for(int i=0;i<5;i++){
                        printf("a[%d]=%d\n",i,*(p++));
            }
}
int main(void)
{
            //test_pointer1();
            test_pointer2();

}

该博客教程视频地址:http://geek99.com/node/998

原文出处:http://geek99.com/node/855#

0 0
原创粉丝点击