Why is the value of i == 0 in this C++ code?

Viewed 1821

I am confused about the following code:

#include <iostream>

int i = 1;
int main()
{
    int i = i;
    std::cout << "i: " << i << "\n";
    return 0;
}

Output:

i: 0

I had expected running the above code would print 1. Can someone please explain the reason for this strange behavior?

1 Answers
Related