Program:
#include <stdio.h>
main ()
{
char x[6] = "12345\0";
char y[6] = "67890\0";
y[7]='A';
printf("X: %s\n",x);
printf("Y: %s\n",y);
}
Program output: X: 1A345 Y: 67890
The following program defines and prints the two variables x and y and gives the above output. Would someone please be able to explain to me why the character A appears in the output of x?
I believe this is due to the way memory is handled in C and writing outside of the bounds of y. I am a computer science student and looking to understand why this happens. Thanks in advance!