+ 2

C appears to make random numbers when not asked

Here is my code: https://code.sololearn.com/cub0yp3QqLNP/#c The %d should be a %f, but when it's %d it makes random numbers in the output. Click run a few times, the first line of the output will change. What's going on here?

5th Feb 2020, 7:18 PM
Klyde
2 Réponses
+ 6
If you don't give your variables an initial value, the bits at that spot of memory will be flipped to 1 or 0 randomly. It's basically how that place looked, before your program came there and claimed that spot. ;-) https://www.sololearn.com/discuss/1654860/?ref=app
5th Feb 2020, 7:20 PM
HonFu
HonFu - avatar
+ 2
Pay attention to the compiler warnings too.
5th Feb 2020, 10:48 PM
Sonic
Sonic - avatar