Scope, Lifetime & Storage Classes

Answer & solution
Official answer: A
Givens and goal
Each program includes stdio.h and has main returning 0. P1: file-scope int a=5; inside main, int a=7;. P2: inside one main block, int a=5; int a=7;. P3: inside one main block, int a=5; float a=7;. Which compiles without a required error? A only P1; B only P2; C only P3; D all.
Approach
Check whether declarations inhabit different scopes or attempt to define the same local identifier twice.
Step-by-step solution
1. P1 has an outer file-scope object and a distinct inner block-scope object. The inner a legally shadows the outer a inside main. The two definitions do not conflict because they are in different scopes.
2. P2 has two initialized definitions of the same ordinary automatic identifier in one block. It is not assignment to an existing object: the repeated type keyword introduces a second declaration/definition, which violates the constraints.
3. P3 also redeclares a in the same block, and additionally changes its type from int to float. This is not legal shadowing, because there is no nested inner block.
4. Only P1 is valid under the intended ANSI-C rules, so A. A compiler may issue a shadowing warning for P1, but an optional warning does not make the program invalid.