What is the output of this code and why .... | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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