471,579 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,579 software developers and data experts.

pls...how this is working...

#define q(k)main(){ return!puts(#k"\nPRABUq("#k")");}

q(#define q(k)main(){return!puts(#k"\nq("#k")");})

guys i'm working on this code.. i got it fromnet.. how this is working.. anyone pls.. it is printing the same content on screen.. how ya.. how it is.. how how how??

please...................
Oct 5 '06 #1
7 2319
hi
#define q(k)main(){ return!puts(#k"\nPRABUq("#k")");}

q(#define q(k)main(){return!puts(#k"\nq("#k")");})

the above code will be converted into following code after preprocessing
here k = #define q(k)main(){return!puts(#k"\nq("#k")");}

and we have defined q(k) in the first line

just substitue k in the text following q(k) in the first line i.e.
q(#define q(k)main(){return!puts(#k"\nq("#k")");})

will be converted as

main()
{
return!puts(#define q(k)main(){return!puts(#k"\nq("#k")");}"\nPRABUq(" #define q(k)main(){return!puts(#k"\nq("#k")");}")");}

so the whole program becomes
#define q(k)main(){ return!puts(#k"\nPRABUq("#k")");}
main()
{
return!puts(#define q(k)main(){return!puts(#k"\nq("#k")");}"\nPRABUq(" #define q(k)main(){return!puts(#k"\nq("#k")");}")");
}

so it just prints the contents in the parenthesis of return!puts

and the output you get is
#define q(k)main(){return!puts(#k"\nq("#k")");}
PRABUq(" #define q(k)main(){return!puts(#k"\nq("#k")");}")")

#k gives the value of k as a stream of characters
But still I do not get what does return!puts() means If anybody knows this plz reply
Oct 5 '06 #2
dush
27
hi

int puts (const char * string ); is prototype and
return value is either non-negative on success or EOF on error.

Theres no reason for error occuring in program above so !puts() equal to 0. Which means it is actually return 0; then and thats the correct way the main function should always end.
Oct 5 '06 #3
hi
#define q(k)main(){ return!puts(#k"\nPRABUq("#k")");}

q(#define q(k)main(){return!puts(#k"\nq("#k")");})

the above code will be converted into following code after preprocessing
here k = #define q(k)main(){return!puts(#k"\nq("#k")");}

and we have defined q(k) in the first line

just substitue k in the text following q(k) in the first line i.e.
q(#define q(k)main(){return!puts(#k"\nq("#k")");})

will be converted as

main()
{
return!puts(#define q(k)main(){return!puts(#k"\nq("#k")");}"\nPRABUq(" #define q(k)main(){return!puts(#k"\nq("#k")");}")");}

so the whole program becomes
#define q(k)main(){ return!puts(#k"\nPRABUq("#k")");}
main()
{
return!puts(#define q(k)main(){return!puts(#k"\nq("#k")");}"\nPRABUq(" #define q(k)main(){return!puts(#k"\nq("#k")");}")");
}

so it just prints the contents in the parenthesis of return!puts

and the output you get is
#define q(k)main(){return!puts(#k"\nq("#k")");}
PRABUq(" #define q(k)main(){return!puts(#k"\nq("#k")");}")")

#k gives the value of k as a stream of characters
But still I do not get what does return!puts() means If anybody knows this plz reply
thankq man.. i was confused for past two days with that code..
i think - - -- actually puts will return the number of characters printed on screen.. here it is greater than 1 so it'll be returned as 0; nothing but after printing , the program gets terminated..

i'm sure abt it.. if any corretion pls.. tell me i'll learn
Oct 6 '06 #4
#define q(k)main(){ return!puts(#k"\nPRABUq("#k")");}

q(#define q(k)main(){return!puts(#k"\nq("#k")");})

guys i'm working on this code.. i got it fromnet.. how this is working.. anyone pls.. it is printing the same content on screen.. how ya.. how it is.. how how how??

please...................
does the stmt
q(#define q(k)main(){return!puts(#k"\nq("#k")");})
works???????
Oct 6 '06 #5
i don't know what it means and i don't even want to bother looking at it. One of the primary aspects of writing code is making it readable and understandable to others. This is not how you write code.
Oct 6 '06 #6
Banfa
9,065 Expert Mod 8TB
i don't know what it means and i don't even want to bother looking at it. One of the primary aspects of writing code is making it readable and understandable to others. This is not how you write code.
Unless you happen to be entering the obviscated code contest :D
Oct 6 '06 #7
tyreld
144 100+
For anybody using a gcc compiler you can use the -E option to only run your code through the preprocessor. It will print out your code with all of the macro substitutions expanded.

"gcc -E file.cpp"
Oct 6 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Mullin Yu | last post: by
5 posts views Thread by Martin Heuckeroth | last post: by
5 posts views Thread by tshad | last post: by
8 posts views Thread by jojobar | last post: by
2 posts views Thread by Don | last post: by
4 posts views Thread by qbproger | last post: by
3 posts views Thread by Jason Huang | last post: by
reply views Thread by WORKING IN FAITH | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.