What will be printed out as a result of the following code execution?
#include <iostream>

using namespace std;

int main()
{
    int i = 0;

    while(i < 10)
    {
        int i = 10;
        cout<<i<<endl;
        i++;
    }

    return 0;
}
Explanation
int i=0 and int i=10 declarations are located in different scopes. i=10 is relevant inside the loop, and i=0 - outside the loop and for the loop itself.

Follow CodeGalaxy

Mobile Beta

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