码迷,mamicode.com
首页 > 其他好文 > 详细

第三次作业

时间:2017-04-04 22:07:31      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:ima   span   void   turn   with   second   alt   总结   exit   

技术分享

#include<stdio.h>
#define b 10                            //定义常量b为10 
void fun(int *q,int arr[]){             
    q = &arr[0];                        //将指针q指向数组arr第一个元素 
    for(int i=0;i<b;i++){
        printf("a[%d]:%d\n",i,*q);
        q++;
    }
}
int main(){
    int a[10],*p;
    p = &a[0]; 
    for(int i=0;i<b;i++)                //初始化数组,将10个元素赋值为1-10 
        a[i]=i+1;
    printf("调用fun函数输出数组a\n");
    fun(p,a);                           //调用函数fun 
    return 0;
} 
调用fun函数输出数组a
a[0]:1
a[1]:2
a[2]:3
a[3]:4
a[4]:5
a[5]:6
a[6]:7
a[7]:8
a[8]:9
a[9]:10

--------------------------------
Process exited after 0.3795 seconds with return value 0
请按任意键继续. . .

总结:*是取值,&是取地址,之前作业中总是混淆,导致程序出错。

第三次作业

标签:ima   span   void   turn   with   second   alt   总结   exit   

原文地址:http://www.cnblogs.com/xBryant/p/6666295.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!