Hi Brian,<br><br>Sounds like you are the path to a true religious experience! ;D<br><br>mod_array() also receives a pass-by-value argument. ;) C copies the pointer. Variable int b[CAP] is really syntactic sugar for int * b. And so is mod_array()&#39;s formal parameter int a[], which is the same as int * a. So the actual and formal parameters match up. And since you are changing what the pointer points to, all is well when the function returns.<br>

<br>However, if you pass an array (say, int a[]) into a function, and then attempt to change what variable a points to, it will last only as long as you are in the function, because a is a copy of the original pointer. For example, a = calloc(4, sizeof(char));. When the function ends, variable a is deleted, control returns to main(), and pointer b still points to its original contents. To get around this, you need to pass a pointer to a pointer into the function (int **b). :P<br>

<br>I am likely proving your point about C being a detriment to the field! ;D Let us know if/when you have a true Lisp epiphany. :) I hear it is quite a revolution in thinking!<br><br><br><br><div class="gmail_quote">On Sun, Feb 28, 2010 at 6:35 PM, Brian Lavender <span dir="ltr">&lt;<a href="mailto:brian@brie.com">brian@brie.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">I think if anything, C has been a certain detriment to the field of<br>
computer science!<br>
<br>
One calls a function and the arguments are passed by value. Call a<br>
function with an array as an argument, and feel free to modify its<br>
contents!<br>
<br>
Certainly, C++ added the idea of reference, but I think Pascal<br>
simplifies these concepts much better. Yet, Pascal seems to be relegated<br>
to the status as a legacy language!<br>
<br>
brian<br>
<br>
<br>
#include &lt;stdio.h&gt;<br>
<br>
#define CAP 10<br>
<br>
void mod_array(int a[])<br>
{<br>
  a[2] = 5;<br>
}<br>
<br>
void trychange(int a)<br>
{<br>
  a = 2;<br>
}<br>
<br>
void reallychange(int *a)<br>
{<br>
  *a = 2;<br>
}<br>
<br>
int main() {<br>
  int b[CAP];<br>
  int c;<br>
  int i;<br>
<br>
  printf(&quot;Load array and change a value\n&quot;);<br>
  for (i=0; i &lt; CAP; i++)<br>
    b[i] = i + 20;<br>
<br>
<br>
  mod_array(b);<br>
<br>
  for (i=0; i &lt; CAP; i++)<br>
    printf(&quot;b[%d] has value of %d\n&quot;,i,b[i]);<br>
<br>
  c = 10;<br>
<br>
  printf(&quot;c has a value of %d\n&quot;,c);<br>
  trychange(c);<br>
<br>
  printf(&quot;c has a value of %d after trychange(c)\n&quot;,c);<br>
<br>
  reallychange(&amp;c);<br>
<br>
  printf(&quot;c has a value of %d after reallychange(&amp;c)\n&quot;,c);<br>
<br>
<br>
}<br>
<br>
--<br>
Brian Lavender<br>
<a href="http://www.brie.com/brian/" target="_blank">http://www.brie.com/brian/</a><br>
<br>
&quot;There are two ways of constructing a software design. One way is to<br>
make it so simple that there are obviously no deficiencies. And the other<br>
way is to make it so complicated that there are no obvious deficiencies.&quot;<br>
<br>
Professor C. A. R. Hoare<br>
The 1980 Turing award lecture<br>
_______________________________________________<br>
vox mailing list<br>
<a href="mailto:vox@lists.lugod.org">vox@lists.lugod.org</a><br>
<a href="http://lists.lugod.org/mailman/listinfo/vox" target="_blank">http://lists.lugod.org/mailman/listinfo/vox</a><br>
</blockquote></div><br>