I can't understand how realloc works.I make this code
#include <stdio.h>
#include <stdlib.h>
Code:
int main(void)
{
int *p=(int *)malloc(5*sizeof(int));
int i;
for(i=0; i<5; i++)
scanf("%d",&p[i]);
for(i=0; i<2; i++)
printf("%d", p[i]);
printf("new elements");
p=(int *)realloc(p,10*sizeof(int));
for(i=5; i<10; i++);
scanf("%d", &p[i]);
return 0;
}
first it asks memory for 5 int.After i put 5 numbers and i print the first 2 numbers.Then use realloc in order to put 5 more numbers but when i give the first number and then enter the programm finishes?Why?I think that should ask me for 5 numbers and not for one.