有以下程序 #include #include void fun(int*p1,int*p2,int*s){ s=(int*)calloc(1,sizeof(int)); *s=*p1+*p2;free(s);}

admin2020-05-19  18

问题 有以下程序
    #include
    #include
    void fun(int*p1,int*p2,int*s){
    s=(int*)calloc(1,sizeof(int));
    *s=*p1+*p2;free(s);}
    main(){
    int a[2]={1,2},b[2]={40,50},*q=a;
    fun(a,b,q);
    pfintf("%d\n",*q);}
    程序运行后的输出结果是

选项 A、41
B、42
C、0
D、1

答案A

解析 主函数定义数组a,b,q指向数组a,调用tun函数以后形参接收实参的数据,p1和p2指向数组a和b,同时s指向数组a,在fun函数中改变了s的指向和赋值,但是在程序调用结束之间形参空间全部释放,因此对于s的指向改动不会对主函数参数构成影响。因此主函数中数去*q的值仍然为1。
转载请注明原文地址:https://kaotiyun.com/show/1rCp777K
0

最新回复(0)