Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

neet to explain how this output is coming

Status
Not open for further replies.

amarg

Programmer
Nov 19, 2002
106
IN
Hi All,

I got one crap code.

code is

main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);}

and output is

main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);}

I don't know how this output is coming from the code.
Please help me to find out the explanation.

Regards,
Amar
 
There are a number of issues with this code. Is it a homework assignment? If not, can you elaborate on what this code is intended to accomplish? Thanks in advance.
 
The code is an example of a quine, a program whose output is its own source code. The poster is only asking how it does that, not what's wrong with it.

The variable
Code:
a
is never declared, so it is treated an an int. The assignment
Code:
a="main(a){printf(a,34,a=%c%s%c,34);}"
luckily appears to be occurring before
Code:
a
is evaluated as the first argument to
Code:
printf
. Since the value of that literal is just a char*, it can be assigned to an int. Not the most correct thing, but it works. The rest is just printf stuff. If you can't figure that out, ask again.

There's gotta be an &quot;#include <stdio.h>&quot; in there, right?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top