双指针作为参数的用法 [英] usage of double pointers as arguments

查看:118
本文介绍了双指针作为参数的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请找到code代码片段,如下所示:

Please find the code snippet as shown below:

    #include <stdio.h>  
    int My_func(int **); 

    int main() 
    { 
         int a =5;
         int *p = &a;
         My_Func(&p);
         printf("The val of *p is %d\n,*p);
    }
    void My_Func(int **p)
    {

         int val = 100;
         int *Ptr = &val;
         *p = Ptr;
    }

如何使用双指针为my_func,并将功能的参数,使得价值变化反映在主函数相同的,但是如果我们使用my_func,并将一个指针主不改变价值呢?请你解释一下我如果可能的例子

How does by using a double pointer as a argument in my_Func function and making change of value reflects the same in the main function but if we use a single pointer in My_Func does not change the value in main?Please do explain me with examples if possible

高级感谢结果
马迪

Advanced thanks
Maddy

推荐答案

在总之,在C当你传递的东西作为一个参数,一个的复制的将被传递给函数。更改副本不影响原始值。

In short, in C when you pass something as a parameter, a copy will be passed to the function. Changing the copy doesn't affect the original value.

然而,如果该值是一个指针,它的的可以改变的。在这种情况下,如果要影响的指针,你需要传递的指向它的指针的到的功能。

However, if the value is a pointer, what it points to can be changed. In this case, if you want to affect the pointer, you need to pass a pointer to it down to the function.

这篇关于双指针作为参数的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆