samedi 11 mars 2017

How local variable hides global variable

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

const int x = 5;
int main(int argc, char** argv)
{
    int x[x];

    int y = sizeof(x) / sizeof(int);

    return 0;
}

y is 5

Q2> What is the value of the local variable x at the end of main?

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

x is undefined

Question> I have problems to understand these two questions. Can someone give me some helps?

Thank you

Aucun commentaire:

Enregistrer un commentaire