函数的参数传递的几种形式(值、地址、引用)及指针基础知识

来源:互联网 发布:java开发求职简历 编辑:程序博客网 时间:2024/06/07 06:54

1,

2,

3,指针作为返回值

   #include<stdio.h>

     int *smaller (int *p1,int *p2);

     int main(void){

      int a;

      int b;

      int *p;

    scanf("%d%d",&a,&b);

      p = smaller (&a,&b);

     printf("*p = %d",*p);

    return 0;

}


int *smaller (int *px,int *py)

{

   return( *px<*py?px:py);

}


//error

//return local pointers: a serious error,take care!

//never return a pointer to a local variable;compare to errors in oc!

float *mistake(){

 float temp = 12;  //Circle c;return &c;

 return &temp;

}

int main()

{

float *p = mistake();

printf("%f\n",*p);//you never know when the system release the tmep or it release after runtime./so we command that never return a point to a local variable;

return;

}

//Points to space on stack that isn't used!



pointers to pointers 




原创粉丝点击