Hi, I am learning C and the book made me type in the included program. Its teh part about using malloc/free functions.
It compiles fine & works but my compiler gives me the following warnings:
1 - implicit declaration of malloc
2 - assignment makes pointer from integer
Above are both about the line which has malloc in it and the last warning is:
3: implict declaration of function free
What exactly is a implicit declaration ? I know malloc returns an adres to allocated memory but why is it implicit ?
The program :
#include <stdio.h>
int main()
{
int index, aant;
float *vec, som;
// invoer arraylengte
printf("Aantal:\n"); scanf("%d",&aant);
// geheugen reserveren
vec = malloc(aant * sizeof(float));
if (!vec)
{
printf("geen geheugen!");
return 1;
}
// gegevens invoeren
for(index = 0; index < aant; index++)
{
printf("floatgetal:\n");
scanf("%g",&vec[index]);
}
// som berekenen
for(index = 0, som = 0; index < aant; index++)
som = som + vec[index];
// resultaat weergeven
printf("som: %g\n",som);
// geheugen vrijgeven
free(vec);
return 0;
}