Code:#include<stdio.h> #include<math.h> void(main(main)) { printf("%-d++",main+=pow(++main/*()*/,++main)); } Output is :- 12++ Please explain it . I could not understand it . Thank you
Code:#include<stdio.h> #include<math.h> void(main(main)) { printf("%-d++",main+=pow(++main/*()*/,++main)); } Output is :- 12++ Please explain it . I could not understand it . Thank you
Last edited by vivekgupta; 06-11-2012 at 07:22 AM.
Your program doesn't even seem to be possible to compile, the parens are unbalanced and the main declaration is just plain wrong.
Unbalanced parentheses aside, this is undefined behavior. Getting rid of the comment, all you're doing is passing the address of main to pow() twice, and incrementing it both times. It's up to the compiler to decide the order, however, you're corrupting any future function calls as the address of main has changed.Code:pow(++main/*()*/,++main);
What the hell?Code:void(main(main))
sorry for wrong code .. me beginner
What ........ing idiot is teaching you this stupid ........?
Basic C programming
It would appear that whoever you're learning from is teaching you stupid C syntax magic tricks, NOT programming.
This path you're on will not in any way lead to employment (if that is indeed your ultimate goal). If this is the only knowledge you will be able to demonstrate, your chances of getting a job will be 0%.
Read the link in my signature.
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.
Thankx buddy
one more programe (Don't be angry please )
Code:#include<stdio.h> void main() { int x; clrscr; x=~!printf; printf("%x",x); }
Output is :- ffffffff
WHY THIS printf CONSIDERED AS TRUE ??
NOT <non-zero> = 0
BITWISE NOT 0 = 0xFFFFFFFF ( or rather all bits turned on )
Devoted my life to programming...
The printf call is considered true because it returns 1.
What you probably meant to ask is why the output of the printf was what it was, but for that... you need to learn what the ! and ~ operators do, as well as what the %x does.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
No i know that what these operators do .But I am asking that printf is considered as TRUE because it return the value of its address in that expression ?? It is ture that every function has it's own memory address???
He didn't say anywhere that he was given this as an assignment or such. He has rather found this puzzle somewhere in the net
The inner "main" is "int argc" (the outer one is hidden) and equals 1.
Assuming the result is 12 it could be compiled like: 3 + pow(3, 2).Code:main+=pow(++main/*()*/,++main)
That does not make sense. In fact, if you are really asking whether the expression printf("%x",x) evaluates to true, then my answer in post #8 applies: the expression evaluates to 1, which is a true value.Originally Posted by vivekgupta
Why do you ask?Originally Posted by vivekgupta
Or something else, due to undefined behaviour.Originally Posted by kmdv
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thanks for the help
Ohh yeah i got it