Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          array-limitations-2.c - Illustration of array limitations in C: Cannot pass as value parameter.Lecture 1 - slide 20 : 34
Program 11

#include <stdio.h>

void f (double p[], int p_lgt){    /* Double the elements in p */
  int i;

  for(i = 0; i < p_lgt; i++)
    p[i] = p[i] * 2;  /* p is NOT a local copy of the
                         actual parameter. It is a pointer
                         to the actual parameter array. */
}

int main(void) {

  double a[10];
  int i;

  for(i = 0; i < 10; i++)  /* Initialization */
    a[i] = i;

  f(a, 10);  /* The array a is not copied to f.
                No compiler errors. No run time errors. */

  for(i = 0; i < 10; i++)
    printf("After calling f: a[%d] = %f\n", i, a[i]);

  return 0;
}