+ 2

C++ bug

I have this code: https://code.sololearn.com/cp6vMUDeEw5g/#cpp I know what the problem is, I have declared the variables after I cout(ed) them. But, I am wondering what 8,0 is that an arbitrary number or if not what is the meaning behind them. Thank you for your assistance.

30th May 2018, 9:07 AM
Bradley
2 Antworten
+ 4
Uninitialised variables in C++ store garbage values, which are whatever values originally stored in the memory address which now happens to be the address of your variables.
30th May 2018, 10:25 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
Bradley x and y are local variables and default value for local variables is garbage value. Best practice is to intialize local variables with null and then after you can start manipulation on that.
30th May 2018, 10:26 AM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar