What is the output of this code and why .... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the output of this code and why ....

int main() { printf("%u",-1); return 0; }

18th Apr 2021, 11:54 AM
A 🌟 P Rana 🔯
A 🌟 P Rana 🔯 - avatar
3 Answers
+ 5
%u stands for unsigned, so if you try to output -1 as unsigned, you will go out of scope value, and print unsigned_max_value If you would try printing -2, you would get unsigned_max_value -1 etc. At least I think it works like that
18th Apr 2021, 12:29 PM
Michal Doruch
+ 2
U mean to say that am i printing the unsigned maximum values of int ?
18th Apr 2021, 12:34 PM
A 🌟 P Rana 🔯
A 🌟 P Rana 🔯 - avatar
+ 2
Yes, you are printing max unsigned int value, which is 2^32-1
18th Apr 2021, 12:41 PM
Michal Doruch