Problems with C ++ Global Areas

I take a test test in C ++, and I am confused with a set of access areas and questions related to the declaration. Both questions are related to each other. I know the answers. What I need is the correct explanation:

What is the value of the local variable x at the end of the main

 int x = 5;
 int main(int argc, char** argv)
 {
    int x = x;
    return 0;
 }

ans: Undefined

What is the value of y at the end of the main?

    const int x = 5;
    int main(int argc, char** argv)
    {
       int x[x];
       int y = sizeof(x) / sizeof(int);
       return 0;
    }

answer: 5

+5
source share
2 answers

It is controlled when the inside appears x(the beginning of its scope). Standard states (3.3.1 in the current standard, 3.3.2 in the upcoming) partially (italics mine):

The declaration point for the name immediately after its full declaration and before its initializer.

int x = x; =, , x, x, . , undefined.

int x[x]; x ;, x .

+8

: 3.3.1 [basic.scope.pdecl]

( 8) ( ), , .

, :

int x = 12;
{ int x = x; }

x () .

[: , . [:

const int i = 2;
{ int i[i]; }

. ]]

.

+8

All Articles