I'm learning some c now, and must do an exercise for the university. I need an double array which should be filld with int values. So I've this.
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] ) {
int size=0, i=0;
printf("Enter size of array: ");
scanf("%d", &size);
double* field = malloc(size * sizeof(double));
double value;
for(i=0; i<size; i++) {
field[i] = i;;
}
for(i=0; i<size; i++) {
printf("Field%i: %d\n",i, field[i]);
}
free(field);
return 0;
}
But, when I execute it all values are set to 0.
Enter size of array: 10
Field0: 0
Field1: 0
Field2: 0
Field3: 0
Field4: 0
Field5: 0
Field6: 0
Field7: 0
Field8: 0
Field9: 0