I have made a dynamic array of integers in C, here is my code
#include <stdio.h>
int main(){
   int count=0, i, input;
   int *myarr;
   myarr=(int*)malloc(4*sizeof(int));
   while(1){
     scanf("%d", &input);
     myarr[count]=input;
     count++;
     if (input == -1) break;
   }
   for (i=0; i<count; i++){
     printf("%d ", myarr[i]);
   }
   return 0;
}
From the code, I thought i clearly made an array of 4 integers only i.e myarr[0] up to myarr[3], how come when i insert even 10 integers, it still prints all of them, it doesn't print garbage as i thought it would after the fourth integer... Maybe i didn't understand the point of dynamic creating an array?? Make me straight please!
 
     
    