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'

11/4/2019 6:34:57 PM

villa then

7 Answers

New Answer

+5

villa then use the correct format specifier printf ("%lu", sizeof(int)); or %zu to avoid the warning you can also explicitly typecast the value to int printf ("%d", (int)sizeof(int));

+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.

+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 👍

+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

+1

I didn't do any changes to the code given under datatypes. How can I avoid or debug the fault causing the warning

+1

Thanks for your answer. Sure, I'll try my best.👍

+1

Thanks for the answer. I'll try