+ 2

int x; x +=10; spits out 4309688. Explanation?

21st May 2017, 11:27 PM
Sohn Jmith
Sohn Jmith - avatar
2 ответов
+ 9
x is not intialised with a value. It could point anywhere in memory. You should always initialise/insert values into variables before using them. try int x=0; x +=10;
21st May 2017, 11:29 PM
jay
jay - avatar
+ 7
You have created the variable but not initialised it. when you type int x; it allocates some memory but does not automatically set the variable to zero (you usually end up with some random value based on what that bit of memory was holding previously). You should initialise it using something like int x=0;
21st May 2017, 11:30 PM
Shane