array-limitations-3.c - Less confusing version that uses pointers. | Lecture 1 - slide 20 : 34 Program 12 |
#include <stdio.h> void f (double *p, int p_lgt){ /* Double the elements in p - notice the pointer notation */ int i; double *q; for(i = 0, q = p; i < p_lgt; i++, q++) *q *= 2; } int main(void) { double a[10]; int i; for(i = 0; i < 10; i++) /* Initialization */ a[i] = i; f(&a[0], 10); /* Alternative parameter. Maybe less confusing */ for(i = 0; i < 10; i++) printf("After calling f: a[%d] = %f\n", i, a[i]); return 0; }