This is C programming code that I have written. When I run this code it shows debug error the visual code is showing this warning as well.
Warning 6385 Reading invalid data from 'my_newarray': the readable size is '4' bytes, but '8' bytes may be read.
My code is:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n;
printf("enter the size of an array: ");
scanf_s("%i", &n);
int my_array[] = { calloc((n + 1), sizeof(int)) };
int my_newarray[] = { calloc((n + 1), sizeof(int)) };
printf("enter only 0s and 1s n times:\n");
for (int i = 0; i < n; i++)
{
scanf_s("%i", &my_array);
}
for (int j = 0; j < n; j++)
{
if (my_array[j] > my_array[j + 1])
{
my_array[j] = my_newarray[j + 1];
}
}
for (int k = 0; k < (n+1); k++)
{
printf("%i\n", my_newarray[k]);
}
free(my_array);
free(my_newarray);
}