[Solved] Declare two or more variables with the same name within the same scope [closed]


That is not possible.

From the standard, 6.7 Declarations (emphasis mine):

If an identifier has no linkage, there shall be no more than one declaration of the identifier (in a declarator or type specifier) with the same scope and in the same name space, …

As to no linkage, 6.2.2 Linkages of identifiers (emphasis mine):

The following identifiers have no linkage: an identifier declared to be anything other than an object or a function; an identifier declared to be a function parameter; a block scope identifier for an object declared without the storage-class specifier extern.


This, for example, is valid at file scope (with internal or external linkage).

int a;
int a;
int a;

However, here all declarations refer to the same object.

1

solved Declare two or more variables with the same name within the same scope [closed]