In the following code, why do multiple declarations (and one definition) work fine for a global variable x but not for a local variable y which is
This is the way defined in the C99 standard, section 6.2.2, part 2:
In the set of translation units and libraries that constitutes an entire program, each declaration of a particular identifier with external linkage denotes the same object or function. Within one translation unit, each declaration of an identifier with internal linkage denotes the same object or function. Each declaration of an identifier with no linkage denotes a unique entity.
The "global" variables x have external linkage, so they denote the same object. The local y variables, on the other hand, has no linkage, so there is a collision.
References: C99 Standard.