What value will be assigned to y ?
const int x = 5;
int main(int argc, char** argv)
{
    int x[x];
    int y = sizeof(x) / sizeof(int);
    return 0;
}
Explanation
In the example above, the int array size is evaluated before local x variable declaration is completed, hence, at the moment of x[] initialization, the global x is not hidden by the local one. Accordingly, sizeof(x) / sizeof(int) evaluates to 5 * sizeof(int) / sizeof(int), hence the result is 5.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes