Write a program that dynamically allocates an array, then free the memory.
Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <stdlib.h>
void main() {
float *tab; /* array of floats */
int i, n; /* n is the size */
printf("Give the size of the array:");
scanf("%d", &n);
tab = (float*) malloc(n*sizeof(float)); /* Allocation*/
for ( i=0; i<n; i++ ) /* filling in the array */
tab[i] = 0.0;
free(tab); /* free the memory */
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Search into a table based on hash coalesced with separated zones