Putting a variable outside of main gives it a global scope which is usually not something we like to practice unless absolutely nessesary (which is almost never the case.
However, pertaining to your post, in your initialization of y you use x++. This changes the value of x. We cannot change values in the global scope as it is not part of the main program. We can only initialize values.