Hi I have this question: Why when I'm allocating memory with malloc for a float array, it allocate more space that i'm requesting? For example in this code i'm trying to allocate a ten "cells" float array, but if I try to access to other cells it returns me no segfault error:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
float *fk_array;
int main(int argc, char** argv){
fk_array = (float *) malloc(10 * sizeof(float));
int i;
fk_array[9] = 2.23;
fk_array[15] = 0.3;
for(i = 0; i<20 ; i++)
printf("%f\n",fk_array[i]);
free(fk_array);
return 1;
}
It returns me :
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
2.230000
0.000000
0.000000
0.000000
0.000000
0.000000
0.300000
0.000000
0.000000
0.000000
0.000000
Where I'm in wrong??