'Problem with Output with Static keyword in C/C++

Output wrt my reasoning should be 0456 but the compiler shows 0415 and I debugged it a little and realised it is targeting both "i" differently.

I'll be grateful if someone can explain the reasoning behind it. Thank You :)

#include <iostream>
using namespace std;
int main()
{
    static int i;
    for(int j = 0; j<2; j++)
    {
        cout << i++;
        static int i = 4;
        cout << i++;
    }
    return 0;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source