Q:

Changing an element value in array does not reflect properly

I need to understand this for my computer science project but I am not sure what is going on, the code is
#include <stdio.h>
void main () {
    char x[6] = "12345\0";
    char y[6] = "67890\0";
    y[7]='A';
    printf("X: %s\n",x);
    printf("Y: %s\n",y);
}

And the output is:

X: 1A345 Y: 67890

Now I'm not sure why the A is in the 2nd element in the x array when I clearly specify y.

A:

What going on is your program showing undefined behaviour.
Remember,

string literals are null-terminated by definition.
C arrays have 0 based. indexing.

To clarify, 

When you try to put a string literal like "12345\0" in an array of 6 char elements, compiler will try to put an extra null after the elements of string literal, which will become a try to access past allocated memory area which in turn invokes undefined behaviour. In case of char x[6] = "12345\0";, you don't need the \0 as a part of the string literal. Also, it's always better to leave the allocation of elements (size of array, in other words) to the compiler when you're providing a string literal for initialization. You can use
char x[ ] = "12345";

Then, having an array of dimension x, the valid access to the array is from index [0] to [x-1]. Accessing outside the allocated memory is UB, again. For example, the above array x, can (should) be accessed safely in a range like
len = strlen(x);      //get the length of the string
for (int i = 0; i < len; i++)
{
     x[i] = i*i;  //access the array

}

That said, please note that the recommended signature of main() is int main(void) 

