Just a bit of fun
- does it compile?Code:#include <stdio.h> int main ( void ) { printf,"%d",32; return 0; }
- does it run?
- what's the output?
Just a bit of fun
- does it compile?Code:#include <stdio.h> int main ( void ) { printf,"%d",32; return 0; }
- does it run?
- what's the output?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
You should have used invisible text or something, so as not to spoil things for the rest of us . . .
http://www.eskimo.com/~scs/cclass/int/sx4db.html
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
EDIT: Ok, so I wasn't supposed to compile it, sorry. I thought maybe it was some experiment or something. I guess I could do like dwks said and color my text invisible.
Last edited by swoopy; 07-11-2007 at 09:09 PM.
I was going to mention the warnings, but you beat me to it.
It's kind of like doing this.
so you get three warnings about statements that do nothing.Code:#include <stdio.h> int main(void) { printf; "%d"; 32; return 0; }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
S'ok. swoopy did exactly the same thing, after all.
What would make it more interesting would be if you used the return value.
I'm sure many people know that printf() returns the number of characters printed (but who ever uses that value?), so you might think that x is set to 2. But no, it's 32.Code:int x = printf, "%d", 32;
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
After your first post, I thought maybe it outputted a space, so I double checked, and it did not.
Here's some more fun:
- what is it printing?Code:#include <stdio.h> int main(void) { char s[4]; return printf(s, sprintf(s, "%s", "%*p"), printf); }
- is the same thing printed after each execution?
- what about after recompiling?
Answer (just guessing, I didn't compile it) in invisible text:
- The address of printf
- almost certainly, unless the dynamic library containing printf() was re-loaded for some reason
- probably, unless printf was linked statically
<end of text>
BTW, you made me re-write my answer several times . . . very nice program.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
jhgjhg
Last edited by robwhit; 07-11-2007 at 08:28 PM. Reason: i suck
Well that's just witchcraft