0

Incrementing

I'm trying to understand how the math works for this, so i understand that x+=5 is the same as saying x=x +5. my issue is that when i put this into my code and run it, the number it gives me is 3. This is without assigning a value to x. My code just looks like: int x; x+=5; cout << x; My question is why do I get 3?

6th Mar 2018, 3:15 AM
Sierra Snyder-Lyon
Sierra Snyder-Lyon - avatar
1 Answer
+ 3
you didn't initialize x with any value so a garbage value was assigned to it Each time you compile this program you will get a different value for x so assign some value to x and try again
6th Mar 2018, 3:38 AM
‎ ‏‏‎Anonymous Guy