差异b / w通过引用调用和通过指针调用 [英] difference b/w call by reference and call by pointer

查看:96
本文介绍了差异b / w通过引用调用和通过指针调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




i我是一名c ++程序员,现在我想学习c语言编程。


所以任何人都可以通过引用解释我与b / w通话的区别和

通过

指针调用(如果可能,请带示例)。

Hi,

i am a c++ programmer,
now i want to learn programming in c also.

so can anybody explain me the difference b/w call by reference and
call by
pointer (with example if possible).

推荐答案

在文章< 11 ********************** @ j27g2000cwj.googlegroups .com> ;,

ravi< dc ********** @ gmail.comwrote:
In article <11**********************@j27g2000cwj.googlegroups .com>,
ravi <dc**********@gmail.comwrote:

>

我是一名c ++程序员,现在我也想学习c语言编程。

所以任何人都可以通过引用解释我与b / w通话的区别和
用指针调用(如果可能的话,带示例)。
>Hi,

i am a c++ programmer,
now i want to learn programming in c also.

so can anybody explain me the difference b/w call by reference and
call by
pointer (with example if possible).



这就像复活节兔子和乔治布什之间的区别。


一个存在而另一个不存在(并且更多'可惜)。


即,你所谓的用指针调用 ;是什么

我们真正喜欢的可靠替代品(通过参考调用)。

It is much like the difference between the Easter Bunny and George Bush.

One exists and the other doesn''t (and more''s the pity).

I.e., what you call "call by pointer" is the poor substitute for what
we''d really like (call by reference).


2月22日,12 :09,ravi < dceravigu ... @ gmail.comwrote:
On 22 Feb, 12:09, "ravi" <dceravigu...@gmail.comwrote:




i是一名c ++程序员,

现在我想学习c语言编程。


所以任何人都可以通过引用解释我与b / w通话的区别和

来电指针(如果可能的话,带示例)。
Hi,

i am a c++ programmer,
now i want to learn programming in c also.

so can anybody explain me the difference b/w call by reference and
call by pointer (with example if possible).



理解C只有一个调用

约定 - 按价值调用可能更有帮助。


当调用C中的函数时,参数将按值传递给它。

- 一种简单的方法(不严格准确,但在我的工作中可行)

意见)是将此视为创建传递数据的副本,并且

通过这些。调用函数无法看到对被调用函数所做的更改。

It''s probably more helpful to understand that C has only one calling
convention - call by value.

When a function in C is called, arguments are passed to it "by value"
- a simple approach (not strictly accurate, but workable in my
opinion) is to regard this as creating copies of the data passed, and
passing these. Changes made in the called function are not visible to
the calling function.


cat ravi.c

#include< stdlib.h>

#include< stdio.h>

void ravi(int a);

int main(void){

int a = 10;

printf(在调用ravi之前的主要部分 - a是%d \ n,a);

ravi(a);

printf(在主要呼叫ravi后 - a是%d \ n,a);

返回EXIT_SUCCESS;

}

void ravi(int a){

printf(" \tin ravi - a最初是%d \\ \\ n,a);

a + = 20;

printf(" \tin ravi - a现在是%d \ n,a);

}

cat ravi.c
#include <stdlib.h>
#include <stdio.h>
void ravi(int a);
int main(void) {
int a = 10;
printf("in main before calling ravi - a is %d\n",a);
ravi(a);
printf("in main after calling ravi - a is %d\n",a);
return EXIT_SUCCESS;
}
void ravi(int a) {
printf("\tin ravi - a is initially %d\n",a);
a += 20;
printf("\tin ravi - a is now %d\n",a);
}


这篇关于差异b / w通过引用调用和通过指针调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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