Page t044, go to NEXT,
PREVIOUS, INDEX
Dynamic Allocation of Arrays
In C one can dynamically allocate arrays
int n = 10;
float *x = (float *) malloc ( n*sizeof(float) );
Or
int n = 10;
float *x;
x = (float *) malloc ( n*sizeof(float) );
- (float *) forces a pointer to
float
- note the use of the sizeof function
- note the use of variable n
To delete a dynamically allocated array use the free function
free (x);
C Course, 22-jan-1997,
Peter Klok,
pfk@hef.kun.nl