+ 3

Where did the second output 1 came from??

printf("%d %d %d",5147483648,10,20);

30th Dec 2019, 7:56 AM
Shubham kumar
Shubham kumar - avatar
60 Antworten
+ 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
30th Dec 2019, 9:43 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 6
Shubham kumar you should definitely be the one to stop, ask Denise Ritchie he will tell you its an undefined behavior
30th Dec 2019, 9:56 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 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
30th Dec 2019, 9:38 AM
Avinesh
Avinesh - avatar
+ 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
30th Dec 2019, 10:05 AM
Ipang
+ 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 : )
30th Dec 2019, 8:37 AM
Ipang
+ 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.
30th Dec 2019, 9:06 AM
Avinesh
Avinesh - avatar
+ 4
Ran the code in C4Droid three times, output are -996556 852516352 1 -3750876 852516352 1 -1889708 852516352 1 How about that?
30th Dec 2019, 9:11 AM
Ipang
+ 4
Shubham kumar %ld and %lu works fine, try compile it on sololearn
30th Dec 2019, 9:35 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 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.
30th Dec 2019, 8:04 AM
Avinesh
Avinesh - avatar
+ 3
Run it on code playground here on sololearn.
30th Dec 2019, 8:09 AM
Avinesh
Avinesh - avatar
+ 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.
30th Dec 2019, 8:41 AM
Shubham kumar
Shubham kumar - avatar
+ 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.
30th Dec 2019, 8:47 AM
Avinesh
Avinesh - avatar
+ 3
First put it as a post there you have an option to insert image. Then share the link of that post here.
30th Dec 2019, 8:49 AM
Avinesh
Avinesh - avatar
+ 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}
30th Dec 2019, 10:19 AM
Ipang
+ 2
No one can understand what you just said.
30th Dec 2019, 8:00 AM
Avinesh
Avinesh - avatar
+ 2
I am asking this question to everyone from past 2 years .No one stated the reason its still mysterious..😂
30th Dec 2019, 8:46 AM
Shubham kumar
Shubham kumar - avatar
30th Dec 2019, 9:00 AM
Shubham kumar
Shubham kumar - avatar
+ 2
Thanks everyone.
30th Dec 2019, 9:49 AM
Shubham kumar
Shubham kumar - avatar
+ 2
Yes i am running in windows
30th Dec 2019, 10:11 AM
Shubham kumar
Shubham kumar - avatar
+ 1
Run this code and explain the output
30th Dec 2019, 8:01 AM
Shubham kumar
Shubham kumar - avatar