#Decrementing an unsigned int that is zero yields -1?

1 messages · Page 1 of 1 (latest)

runic rain
#

Can someone explain why this prints -1, and not the max ul? was i coerced to signed?

#include "stdio.h"
#include "stdint.h"

int main(){
        unsigned long i = 0;
        i--;
        printf(" %ld\n", i);
        return 0;
}
knotty ivyBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

junior schooner
#

%d is the formatter for a signed decimal integer. use %u for unsigned decimal integers

#

the formatters tell printf how to interpret each argument, so yes it did get converted

runic rain
#

🙏

#

thank you

#

!solved