I have a for loop that resizes and appends a number to an dynamically sized array. However the array only repeats a couple times then the program ends.
#include<stdio.h>
#include<stdlib.h>
int main() {
int *primes = (int*)malloc(sizeof(int));
for (int i = 0; i < 15000; i++) {
primes[i] = i;
primes = (int*)realloc(primes, (i+2)*sizeof(int));
}
for (int i = 0; i < sizeof(primes)/sizeof(int); i++) {
printf("%i, ", primes[i]);
}
free(primes);
return 0;
}
This prints 0, 1,
then exits
Why does it not continue to 15000?