What is the warning produced for "sizeof(int)" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the warning produced for "sizeof(int)"

A warning is displayed saying that %d expects output of type 'int' but argument two has 'long unsigned int'

4th Nov 2019, 6:34 PM
villa then
villa then - avatar
6 Answers
+ 4
It means you are using an inappropriate format specifier for the second argument (argument two). In this case the supplied format specifier was supposed to be used for int (signed int) type; while the data to be formatted was of unsigned long type. Why we get this message? the compiler wants to warn us, that an unsigned type value being displayed using format specifier dedicated for signed type may give different (or wrong) output, which leads to misunderstanding and unwanted output.
4th Nov 2019, 6:49 PM
Ipang
+ 3
Occasionally, changes in compiler (by an upgrade) may trigger issues. What was previously considered OK (not giving warning) may be considered differently with the new version (or standard). To avoid this warning, basically we need to make sure that each supplied format specifier matches the type of the argument that is to be formatted. That is, use x-type format specifier to format an argument of x-type, not one of y-type or z-type. You can edit your original question to include your code link. Or if it's rather short, copy-paste a portion of the code that triggered the warning. This way the context clarity of the question is improved, given the code or a portion of it 👍
4th Nov 2019, 7:07 PM
Ipang
+ 2
villa then For future reference, if your question concerns a code then attach the saved code link. If your question concerns a lesson then attach lessons link. And more importantly, specify the language in the Relevant Tags section to clarify context. Follow these guides for posting a question and how to share links 👍 https://www.sololearn.com/Discuss/333866/?ref=app https://www.sololearn.com/post/74857/?ref=app
4th Nov 2019, 7:23 PM
Ipang
+ 1
I didn't do any changes to the code given under datatypes. How can I avoid or debug the fault causing the warning
4th Nov 2019, 6:54 PM
villa then
villa then - avatar
+ 1
Thanks for your answer. Sure, I'll try my best.👍
4th Nov 2019, 7:11 PM
villa then
villa then - avatar
+ 1
Thanks for the answer. I'll try
5th Nov 2019, 5:05 AM
villa then
villa then - avatar