+ 3
Where did the second output 1 came from??
printf("%d %d %d",5147483648,10,20);
49 Respuestas
+ 6
English bro, ~ swim ~ it seem i get what he is trying to point out, according to his screenshot an undefined behavior happens, but he do not know why it affects the other 2 specifier ahead which he thought are going to print fine
+ 6
Shubham kumar you should definitely be the one to stop, ask Denise Ritchie he will tell you its an undefined behavior
+ 5
Ipang ~ swim ~ ✳AsterisK✳
and me all got the right answer while running it. The behaviour without changing the format specifier is undefined as said by most of us.
You cannot predict the output.
It's as simple as that.
Do you get it Shubham kumar
+ 5
Just a little note, remembering back before SoloLearn shifted to Linux, C++ compiler on the Windows server understands %I64D format specifier for signed 64bits integer, and %I64U format specifier for unsigned 64bits integer.
Just in case you are running on Windows Shubham kumar
+ 4
Shubham kumar
The use of inappropriate format specifier can cause unpredictable issues. Avinesh was correct in saying this has to do with data type range. Although the output may differ amongst compilers, the remedy is only to use the appropriate format specifier for the data to be printed : )
+ 4
As long as that line is concerned, it just needs an "%ld" to print the first number and the rest should be fine.
But that is an undefined behaviour.
+ 4
Ran the code in C4Droid three times, output are
-996556 852516352 1
-3750876 852516352 1
-1889708 852516352 1
How about that?
+ 4
Shubham kumar %ld and %lu works fine, try compile it on sololearn
+ 3
Kindly check for the range of integer type variable. I do not get the error you mentioned but the first number is out of range of int type.
+ 3
Run it on code playground here on sololearn.
+ 3
Ipang Yes that is correct to use appropriate format specifier but using %d for long ranges also does'nt gives an error .
And there must be some reason for the reason behind different output .
Because nothing in programming is undefned everything happens for a reason.
I just wanted to know the reason.
+ 3
Shubham kumar a lot of things in programming are undefined, it is just that many are not aware of it.
It would be better if you can just share a screenshot of your result here because the response you are receiving are not on stable grounds.
+ 3
First put it as a post there you have an option to insert image.
Then share the link of that post here.
+ 3
Try %I64D or %I64U as the format specifier for the first value (the big number) in case %lld or llu is not recognised, or aren't working as expected. That's what I mean Shubham kumar
{unsub}
+ 2
No one can understand what you just said.
+ 2
I am asking this question to everyone from past 2 years .No one stated the reason its still mysterious..😂
+ 2
Thanks everyone.
+ 2
Yes i am running in windows
+ 1
Run this code and explain the output