473,394 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 2545
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

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

Similar topics

6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
4
by: qbproger | last post by:
I'm developing a plugin for some software. The previous version of the software didn't require a start in directory to be set. This allowed me to leave the working directory to the default in the...
3
by: Jason Huang | last post by:
Hi, In our C# Windows Form application, we are using the SQL Server 2000 as the database server. The Database table MyTable has a field RegistrationDate which represents the Date a client comes...
0
by: WORKING IN FAITH | last post by:
three years I LOVE You Monica More options 1 message - Collapse all WORKING IN FAITH View profile More options Nov 13, 11:29 am three years I LOVE You Monica
3
by: lds | last post by:
On our server we have both applications that have been migrated to use v2.0 of the framework as well as apps that have not yet been migrated and still use 1.1. When I tried to deploy my v2.0 app...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.