Yes, correct. The answer might very much be architecture specific. I didn't know you could printf a null pointer in the first place I was expecting both of them to crash. Now to see whether this is specified, implementation-defined, undefined behavior, or just a compiler bug.
Undefined behavior means it might crash, it might appear to succeed, it might erase your hard drive, or it might show sunshine and puppies on your screen.
You never know. Per 7. Show 5 more comments. Active Oldest Votes. Comments were added by me. Improve this answer. Chris Reuter Chris Reuter 1, 9 9 silver badges 8 8 bronze badges. Good answer though R. But there's nothing weird about the newline. By contrast, fputs prints to a specified file and doesn't add a newline. I didn't know about the newline until you told me. I guess it's because I always just used fputs instead.
Add a comment. This is what I was looking for. Is this behaviuor calling puts and printf in different scenario part of C standard. Or a compiler can chose its own mechanisms. The compiler can make any transformation that does not change the behavior of a valid program. Here it changed the behavior of an invalid one.
Section 7. Jonathan Leffler Jonathan Leffler k gold badges silver badges bronze badges. I'm adding this as an extra note: that 4. In my comment the word actually is maybe superfluous. November 25, Sign up for our monthly newsletter to get notified of new articles.
Check out these popular articles! Why developers need to move beyond software testing to validate a trusted execution environment. Connect with us! Linkedin Twitter Youtube. Sign up for our monthly newsletter. Get notified of new articles! GCC prints null. What is NULL? NULL is a macro defined by several headers including stdio.
It is a value which is "guaranteed to compare unequal to a pointer to any object or function", as per C standard. That is, a null pointer points definitively nowhere - it is never the address of any object or function. Here is a program to demonstrate the effect of passing null pointer to printf with different format specifiers.
Anirudh Khanna is a Computer Science student and a geek who firmly believes in the awesomeness of technology!
0コメント