samedi 28 mars 2015

C++ int with preceding 0 changes entire value


I have this very strange problem where if I declare an int like so



int time = 0110;


and then display it to the console the value returned is 72. However when I remove the 0 at the front so that int time = 110; the console then displays 110 like expected.


Two things I'd like to know, first of all why it does this with a preceding 0 at the start of the int and is there a way to stop it so that 0110 at least equals 110? Secondly is there any way to keep it so that 0110 returns 0110?

If you take a crack guess at the variable name I'm trying to do operations with 24hr time, but at this point any time before 1000 is causing problems because of this.


Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire