The problem I'm facing is that in this loop, j gets assigned the value of 3 (That's right) and i gets assigned the value of -858993460 (That's wrong!)
Where am I going wrong? I'm sorry if it's a very trivial mistake, I'm very much a beginner.

-858993460 corresponds to the bit pattern held by the value 0xCCCCCCCC, which is the value uninitialized variables are given in VC++ debug builds. I think you're looking at the value of i in the debugger before it officially exists.