#include <stdio.h>
#include <stdlib.h>
int main(void) {
double *array;
unsigned int size;
printf("Choose size for your number array: ");
scanf("%u", &size);
array = malloc(sizeof(double) * size);
return 0;
}
I memory allocated sizeof(double) * size, which I don't know if sizeof(double) is necessary, but sizeof(double) is not 1, so I don't know if I should either:
for (int i = 0; i < size; i++) {
}
For loop through size without multiply it with sizeof(double), or:
for (int i = 0; i < sizeof(double) * size; i++) {
}
For loop and multiply size with sizeof(double) as well? The reason why I'm asking is because I really want to be careful and prevent going over size.
For loop without multiplying sizeof(double) or not?
doubles are there in your array?sizeorsize * sizeof(double)?sizeof(char)would be 1, butsizeof(double)won't be 1 (Idk if it is 8), so am I supposed to multiply bysizeof(double)or what? I'm starting to get confused on the purpose of multiplying sizeof(double).i.arr = malloc(sizeof *arr * size);. It is the right size for an arraysizeof whatever typearrpoints to.