Category talk:C: Difference between revisions

Line 15:
: The only way to do a reference to a "thing" is a pointer indeed. In C this is explicit. In other languages it is not... But pointers are the way C calls "by reference", so function(&c) is a passing of c by reference... then the reference can be dereferenced... not simulation! --[[User:ShinTakezou|ShinTakezou]] 13:46, 31 May 2009 (UTC)
:: That's not call by reference. That's passing the address of the thing by value... ;-) —[[User:Dkf|Dkf]] 13:55, 31 May 2009 (UTC)
::: And what do you think that it works in other languages the "pass by reference"? In C it is explicit the fact that there are pointers at work. In other languages it is not explicit, it's hidden in layers of abstraction... but it is what it happens at the end of the games. No way to get out.
<lang c>int x;
int *rx;
x = 5;
rx = &x;</lang>
::: Now, rx can be used as a reference to x. Similarly, a lang like Perl has the "\" "operator", and the "semantic" (maybe the wrong word, I don't know) is the same of the pointers...
<lang perl>my @arr = ( 1, 2, 3 );
my $ref = \@arr;
a_function($ref); # the same as C, $ref is a reference, ... but it is passed "by value", i.e.
# there's no difference with the following
my $scalar = 12;
a_function($scalar);
</lang>