An example of call by value would be:
Code:
void foo(int v)
{
/* v's value is a copy of x's value */
/* ... */
}
/* ... */
int x = 0;
foo(x);
An example of simulated call by reference in C would be:
Code:
void bar(int *p)
{
/* p refers to x, but pointer notation is used */
/* ... */
}
/* ... */
int x = 0;
bar(&x);
An example of simulated call by copy-restore in C would be:
Code:
void baz(int *p)
{
/* copy */
int *local = malloc(sizeof(int));
if (local == NULL)
{
return;
}
*local = *p;
/* ... */
/* restore */
*p = *local;
free(local);
}